diff options
author | Chris Wilson <chris+github@qwirx.com> | 2015-07-31 06:40:34 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2015-07-31 06:40:34 +0000 |
commit | 6f071a6b68be4c61b40e9a4a0cd27deb46fd4fcd (patch) | |
tree | 043247b658c94b74365961b645575d9ecd92d6f2 /lib/httpserver | |
parent | 8231689bc61f8fadb94e92fe35529cf8b378ab1d (diff) |
Add a method on S3Client to check HTTPResponse for errors.
Throws a suitable exception if the response status code is not 200 OK.
Diffstat (limited to 'lib/httpserver')
-rw-r--r-- | lib/httpserver/S3Client.cpp | 24 | ||||
-rw-r--r-- | lib/httpserver/S3Client.h | 1 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/httpserver/S3Client.cpp b/lib/httpserver/S3Client.cpp index 59044573..c9202d36 100644 --- a/lib/httpserver/S3Client.cpp +++ b/lib/httpserver/S3Client.cpp @@ -245,4 +245,26 @@ HTTPResponse S3Client::SendRequest(HTTPRequest& rRequest, } return response; -} +} + +// -------------------------------------------------------------------------- +// +// Function +// Name: S3Client::CheckResponse(HTTPResponse&, +// std::string& message) +// Purpose: Check the status code of an Amazon S3 response, and +// throw an exception with a useful message (including +// the supplied message) if it's not a 200 OK response. +// Created: 26/07/15 +// +// -------------------------------------------------------------------------- + +void S3Client::CheckResponse(const HTTPResponse& response, const std::string& message) const +{ + if(response.GetResponseCode() != HTTPResponse::Code_OK) + { + THROW_EXCEPTION_MESSAGE(HTTPException, RequestFailedUnexpectedly, + message); + } +} + diff --git a/lib/httpserver/S3Client.h b/lib/httpserver/S3Client.h index 3c4126ac..2d3f71cf 100644 --- a/lib/httpserver/S3Client.h +++ b/lib/httpserver/S3Client.h @@ -51,6 +51,7 @@ class S3Client HTTPResponse GetObject(const std::string& rObjectURI); HTTPResponse PutObject(const std::string& rObjectURI, IOStream& rStreamToSend, const char* pContentType = NULL); + void CheckResponse(const HTTPResponse& response, const std::string& message) const; private: HTTPServer* mpSimulator; |