use http::StatusCode;
use krabby_details::{ProblemDetails, ValidationErrors};
pub(crate) struct InvalidRequest(ProblemDetails<ValidationErrors>);
impl InvalidRequest {
pub(crate) fn new(errors: ValidationErrors) -> Self {
Self(ProblemDetails {
type_: "invalid_request".into(),
status: Self::status().as_u16(),
title: "The request is invalid".into(),
extensions: Some(errors),
detail: "The request is either malformed or doesn't match the expected schema".into(),
})
}
pub(crate) fn status() -> StatusCode {
StatusCode::BAD_REQUEST
}
pub(crate) fn into_inner(self) -> ProblemDetails<ValidationErrors> {
self.0
}
}
impl axum_core::response::IntoResponse for InvalidRequest {
fn into_response(self) -> axum_core::response::Response {
self.into_inner().into_response()
}
}