| /** | |
| * @file exceptions.hpp | |
| * @brief Custom exception hierarchy. | |
| */ | |
| namespace app::utils { | |
| class AppException : public std::runtime_error { | |
| public: | |
| AppException(const std::string& msg, int code = 500) | |
| : std::runtime_error(msg), status_code_(code) {} | |
| int status_code() const noexcept { return status_code_; } | |
| private: | |
| int status_code_; | |
| }; | |
| class ValidationError : public AppException { | |
| public: | |
| explicit ValidationError(const std::string& msg) | |
| : AppException(msg, 400) {} | |
| }; | |
| class NotFoundError : public AppException { | |
| public: | |
| explicit NotFoundError(const std::string& resource) | |
| : AppException(resource + " not found", 404) {} | |
| }; | |
| class AuthenticationError : public AppException { | |
| public: | |
| AuthenticationError() | |
| : AppException("Authentication failed", 401) {} | |
| }; | |
| } // namespace app::utils | |