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,