|
|
@@ -5,16 +5,24 @@
|
|
|
|
|
|
namespace svapi {
|
|
|
|
|
|
-enum class ErrCode { BadRequest, Unauthorized, Forbidden, NotFound, Unprocessable, TooManyRequests, Unavailable, Internal };
|
|
|
+enum class ErrCode { BadRequest, Unauthorized, Forbidden, NotFound, Conflict,
|
|
|
+ Unprocessable, TooManyRequests, Unavailable, Internal };
|
|
|
|
|
|
int httpStatus(ErrCode code);
|
|
|
-nlohmann::json errorBody(const std::string& code, const std::string& message);
|
|
|
+
|
|
|
+/// `details` is merged into the error object as `error.details` when non-empty.
|
|
|
+/// Used for machine-readable payloads (colliding ids, relation impacts) that
|
|
|
+/// would otherwise be flattened into the message string.
|
|
|
+nlohmann::json errorBody(const std::string& code, const std::string& message,
|
|
|
+ const nlohmann::json& details = nlohmann::json::object());
|
|
|
|
|
|
struct ApiError : std::runtime_error {
|
|
|
ErrCode code;
|
|
|
std::string slug;
|
|
|
- ApiError(ErrCode c, std::string slug_, const std::string& msg)
|
|
|
- : std::runtime_error(msg), code(c), slug(std::move(slug_)) {}
|
|
|
+ nlohmann::json details; // optional structured payload; empty object = omitted
|
|
|
+ ApiError(ErrCode c, std::string slug_, const std::string& msg,
|
|
|
+ nlohmann::json det = nlohmann::json::object())
|
|
|
+ : std::runtime_error(msg), code(c), slug(std::move(slug_)), details(std::move(det)) {}
|
|
|
};
|
|
|
|
|
|
} // namespace svapi
|