File size: 904 Bytes
3b9a06c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | /**
* @file exceptions.hpp
* @brief Custom exception hierarchy.
*/
#pragma once
#include <stdexcept>
#include <string>
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
|