errors.hpp 550 B

1234567891011121314151617181920
  1. #pragma once
  2. #include <stdexcept>
  3. #include <string>
  4. #include <nlohmann/json.hpp>
  5. namespace svapi {
  6. enum class ErrCode { BadRequest, Unauthorized, NotFound, Unprocessable, Unavailable, Internal };
  7. int httpStatus(ErrCode code);
  8. nlohmann::json errorBody(const std::string& code, const std::string& message);
  9. struct ApiError : std::runtime_error {
  10. ErrCode code;
  11. std::string slug;
  12. ApiError(ErrCode c, std::string slug_, const std::string& msg)
  13. : std::runtime_error(msg), code(c), slug(std::move(slug_)) {}
  14. };
  15. } // namespace svapi