use crate::CborRejection;
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
#[derive(Debug, Default)]
pub struct FailedToParseCbor;
impl From<FailedToParseCbor> for CborRejection {
fn from(x: FailedToParseCbor) -> Self {
CborRejection::FailedToParseCbor(x)
}
}
impl IntoResponse for FailedToParseCbor {
fn into_response(self) -> Response {
(Self::status(), Self::body_text()).into_response()
}
}
impl FailedToParseCbor {
#[must_use]
pub fn body_text() -> &'static str {
"Invalid Request"
}
#[must_use]
pub fn status() -> StatusCode {
StatusCode::BAD_REQUEST
}
}
#[derive(Debug, Default)]
pub struct MissingCBorContentType;
impl From<MissingCBorContentType> for CborRejection {
fn from(x: MissingCBorContentType) -> Self {
CborRejection::MissingCBorContentType(x)
}
}
impl IntoResponse for MissingCBorContentType {
fn into_response(self) -> Response {
(Self::status(), Self::body_text()).into_response()
}
}
impl MissingCBorContentType {
#[must_use]
pub fn body_text() -> &'static str {
"Expected request with `content-type: application/cbor`"
}
#[must_use]
pub fn status() -> StatusCode {
StatusCode::UNSUPPORTED_MEDIA_TYPE
}
}