| 123456789101112131415161718192021222324252627 |
- #include "errors.hpp"
- namespace svapi {
- int httpStatus(ErrCode code) {
- switch (code) {
- case ErrCode::BadRequest: return 400;
- case ErrCode::Unauthorized: return 401;
- case ErrCode::Forbidden: return 403;
- case ErrCode::NotFound: return 404;
- case ErrCode::Conflict: return 409;
- case ErrCode::Unprocessable: return 422;
- case ErrCode::TooManyRequests: return 429;
- case ErrCode::Unavailable: return 503;
- case ErrCode::Internal: return 500;
- }
- return 500;
- }
- nlohmann::json errorBody(const std::string& code, const std::string& message,
- const nlohmann::json& details) {
- nlohmann::json err{{"code", code}, {"message", message}};
- if (!details.is_null() && !details.empty()) err["details"] = details;
- return nlohmann::json{{"error", err}};
- }
- } // namespace svapi
|