@@ -8,8 +8,9 @@ int httpStatus(ErrCode code) {
case ErrCode::Unauthorized: return 401;
case ErrCode::Forbidden: return 403;
case ErrCode::NotFound: return 404;
- case ErrCode::Unprocessable: return 422;
- case ErrCode::Unavailable: return 503;
+ case ErrCode::Unprocessable: return 422;
+ case ErrCode::TooManyRequests: return 429;
+ case ErrCode::Unavailable: return 503;
case ErrCode::Internal: return 500;
}
return 500;
@@ -5,7 +5,7 @@
namespace svapi {
-enum class ErrCode { BadRequest, Unauthorized, Forbidden, NotFound, Unprocessable, Unavailable, Internal };
+enum class ErrCode { BadRequest, Unauthorized, Forbidden, NotFound, Unprocessable, TooManyRequests, Unavailable, Internal };
int httpStatus(ErrCode code);
nlohmann::json errorBody(const std::string& code, const std::string& message);
@@ -26,3 +26,7 @@ TEST(Errors, ApiErrorCarriesFields) {
TEST(Errors, ForbiddenIs403) { EXPECT_EQ(httpStatus(svapi::ErrCode::Forbidden), 403); }
+
+TEST(Errors, TooManyRequestsMapsTo429) {
+ EXPECT_EQ(svapi::httpStatus(svapi::ErrCode::TooManyRequests), 429);
+}