|
1 | 1 | #ifndef DOCKER_EXCEPTION_H |
2 | 2 | #define DOCKER_EXCEPTION_H |
3 | 3 |
|
4 | | -class DockerException { |
| 4 | +#include <exception> |
| 5 | +#include <string> |
5 | 6 |
|
| 7 | +namespace dockercpp { |
| 8 | + |
| 9 | +class DockerException : public std::runtime_error { |
| 10 | +public: |
| 11 | + DockerException(const std::string& message) |
| 12 | + : std::runtime_error(message), statusCode_(0) {} |
| 13 | + |
| 14 | + DockerException(const std::string& message, int statusCode) |
| 15 | + : std::runtime_error(message), statusCode_(statusCode) {} |
| 16 | + |
| 17 | + DockerException(const std::string& message, int statusCode, const std::string& responseBody) |
| 18 | + : std::runtime_error(message), |
| 19 | + statusCode_(statusCode), |
| 20 | + responseBody_(responseBody) {} |
| 21 | + |
| 22 | + int getStatusCode() const { return statusCode_; } |
| 23 | + const std::string& getResponseBody() const { return responseBody_; } |
| 24 | + |
| 25 | +private: |
| 26 | + int statusCode_; |
| 27 | + std::string responseBody_; |
| 28 | +}; |
| 29 | + |
| 30 | +// Specific Docker exceptions |
| 31 | +class DockerClientException : public DockerException { |
| 32 | +public: |
| 33 | + explicit DockerClientException(const std::string& message) |
| 34 | + : DockerException(message) {} |
| 35 | +}; |
| 36 | + |
| 37 | +class NotModifiedException : public DockerException { |
| 38 | +public: |
| 39 | + NotModifiedException(const std::string& message) |
| 40 | + : DockerException(message, 304) {} |
6 | 41 | }; |
7 | 42 |
|
| 43 | +class NotFoundException : public DockerException { |
| 44 | +public: |
| 45 | + NotFoundException(const std::string& message) |
| 46 | + : DockerException(message, 404) {} |
| 47 | +}; |
| 48 | + |
| 49 | +class ConflictException : public DockerException { |
| 50 | +public: |
| 51 | + ConflictException(const std::string& message) |
| 52 | + : DockerException(message, 409) {} |
| 53 | +}; |
| 54 | + |
| 55 | +class InternalServerErrorException : public DockerException { |
| 56 | +public: |
| 57 | + InternalServerErrorException(const std::string& message) |
| 58 | + : DockerException(message, 500) {} |
| 59 | +}; |
| 60 | + |
| 61 | +} // namespace dockercpp |
| 62 | + |
8 | 63 | #endif |
0 commit comments