dont need thiserror for this really

This commit is contained in:
slonkazoid 2025-01-30 21:30:14 +03:00
parent 02496d220a
commit 0c184ae42b
Signed by: slonk
SSH key fingerprint: SHA256:tbZfJX4IOvZ0LGWOWu5Ijo8jfMPi78TU7x1VoEeCIjM

View file

@ -4,7 +4,6 @@ use axum::http::request::Parts;
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use serde::de::DeserializeOwned;
use thiserror::Error;
pub struct SafePath<T>(pub T);
@ -28,16 +27,25 @@ where
}
}
#[derive(Error, Debug)]
#[derive(Debug)]
pub enum SafePathRejection {
#[error("path contains invalid characters")]
Invalid,
#[error(transparent)]
PathRejection(#[from] PathRejection),
PathRejection(PathRejection),
}
impl From<PathRejection> for SafePathRejection {
fn from(value: PathRejection) -> Self {
Self::PathRejection(value)
}
}
impl IntoResponse for SafePathRejection {
fn into_response(self) -> Response {
(StatusCode::BAD_REQUEST, self.to_string()).into_response()
match self {
SafePathRejection::Invalid => {
(StatusCode::BAD_REQUEST, "path contains invalid characters").into_response()
}
SafePathRejection::PathRejection(err) => err.into_response(),
}
}
}