Full extractor responses.

This commit is contained in:
2026-10-11 08:45:00 +02:00
parent e0eb259182
commit 46a127fbf1
6 changed files with 24 additions and 24 deletions
+18 -18
View File
@@ -8,6 +8,20 @@ use axum::{
use super::extractors::{AuthError, AuthHeaderError, BearerError, ExtractorError};
use crate::{domain::DomainError, error::AppError, repository::RepositoryError};
impl IntoResponse for AppError {
fn into_response(self) -> Response {
let (status, message) = self.client_response();
if status.is_server_error() {
tracing::error!(error = ?self, %status, "request failed");
} else {
tracing::debug!(error = ?self, %status, "request rejected");
}
error_response(status, message)
}
}
impl ClientError for AppError {
fn client_response(&self) -> (StatusCode, Cow<'_, str>) {
match self {
@@ -42,10 +56,10 @@ impl ClientError for ExtractorError {
fn client_response(&self) -> (StatusCode, Cow<'_, str>) {
match self {
Self::Authorization(error) => error.client_response(),
Self::Form(_) => (StatusCode::BAD_REQUEST, "Form error".into()),
Self::Json(_) => (StatusCode::BAD_REQUEST, "Json error".into()),
Self::Path(_) => (StatusCode::BAD_REQUEST, "Path error".into()),
Self::Query(_) => (StatusCode::BAD_REQUEST, "Query error".into()),
Self::Form(error) => (StatusCode::BAD_REQUEST, error.to_string().into()),
Self::Json(error) => (StatusCode::BAD_REQUEST, error.to_string().into()),
Self::Path(error) => (StatusCode::BAD_REQUEST, error.to_string().into()),
Self::Query(error) => (StatusCode::BAD_REQUEST, error.to_string().into()),
}
}
}
@@ -130,20 +144,6 @@ fn internal_error() -> (StatusCode, Cow<'static, str>) {
)
}
impl IntoResponse for AppError {
fn into_response(self) -> Response {
let (status, message) = self.client_response();
if status.is_server_error() {
tracing::error!(error = ?self, %status, "request failed");
} else {
tracing::debug!(error = ?self, %status, "request rejected");
}
error_response(status, message)
}
}
#[derive(serde::Serialize)]
struct ErrorResponse {
pub message: String,
+2 -2
View File
@@ -62,8 +62,8 @@ pub enum AuthHeaderError {
#[error("missing header")]
Missing,
#[error("invalid encoding")]
NotAscii(#[source] ToStrError),
#[error(transparent)]
NotAscii(#[from] ToStrError),
#[error("malformed value")]
MalformedValue,
+1 -1
View File
@@ -24,7 +24,7 @@ where
}
#[derive(Debug, thiserror::Error)]
#[error("form error")]
#[error(transparent)]
pub struct FormError(#[from] axum::extract::rejection::FormRejection);
impl IntoResponse for FormError {
+1 -1
View File
@@ -32,7 +32,7 @@ where
}
#[derive(Debug, thiserror::Error)]
#[error("json error")]
#[error(transparent)]
pub struct JsonError(#[from] axum::extract::rejection::JsonRejection);
impl IntoResponse for JsonError {
+1 -1
View File
@@ -25,7 +25,7 @@ where
}
#[derive(Debug, thiserror::Error)]
#[error("path error")]
#[error(transparent)]
pub struct PathError(#[from] axum::extract::rejection::PathRejection);
impl IntoResponse for PathError {
+1 -1
View File
@@ -25,7 +25,7 @@ where
}
#[derive(Debug, thiserror::Error)]
#[error("query error")]
#[error(transparent)]
pub struct QueryError(#[from] axum::extract::rejection::QueryRejection);
impl IntoResponse for QueryError {