backend 409 on document conflict

This commit is contained in:
2025-11-02 13:22:16 +01:00
parent 9ddaa59155
commit a30b6eaa02
2 changed files with 22 additions and 12 deletions
+11
View File
@@ -4,6 +4,7 @@ use axum::{
Json,
};
use serde::Serialize;
use serde_json::Value;
use std::fmt::Display;
pub type AppResult<T> = Result<T, AppError>;
@@ -13,6 +14,7 @@ pub struct AppError {
status: StatusCode,
message: String,
code: Option<String>,
details: Option<Value>,
}
impl AppError {
@@ -21,6 +23,7 @@ impl AppError {
status,
message: message.into(),
code: None,
details: None,
}
}
@@ -48,6 +51,11 @@ impl AppError {
self.code = Some(code.into());
self
}
pub fn with_details(mut self, details: Value) -> Self {
self.details = Some(details);
self
}
}
impl IntoResponse for AppError {
@@ -56,6 +64,7 @@ impl IntoResponse for AppError {
let body = Json(ErrorResponse {
error: self.message,
code: self.code,
details: self.details,
});
(status, body).into_response()
}
@@ -66,6 +75,8 @@ struct ErrorResponse {
error: String,
#[serde(skip_serializing_if = "Option::is_none")]
code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
details: Option<Value>,
}
impl From<diesel::result::Error> for AppError {