Skip to main content

systemprompt_models/api/errors/
status.rs

1//! HTTP status mapping for [`ErrorCode`].
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use http::StatusCode;
7
8use super::ErrorCode;
9
10impl ErrorCode {
11    #[must_use]
12    pub const fn status_code(&self) -> StatusCode {
13        match self {
14            Self::NotFound => StatusCode::NOT_FOUND,
15            Self::BadRequest => StatusCode::BAD_REQUEST,
16            Self::Unauthorized => StatusCode::UNAUTHORIZED,
17            Self::Forbidden => StatusCode::FORBIDDEN,
18            Self::ValidationError => StatusCode::UNPROCESSABLE_ENTITY,
19            Self::ConflictError => StatusCode::CONFLICT,
20            Self::PayloadTooLarge => StatusCode::PAYLOAD_TOO_LARGE,
21            Self::Locked => StatusCode::LOCKED,
22            Self::RateLimited => StatusCode::TOO_MANY_REQUESTS,
23            Self::Gone => StatusCode::GONE,
24            Self::ServiceUnavailable => StatusCode::SERVICE_UNAVAILABLE,
25            Self::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
26        }
27    }
28}