feat: better error handling
This commit is contained in:
parent
b8e64e2d2c
commit
5a7691062b
1 changed files with 15 additions and 1 deletions
16
src/error.rs
16
src/error.rs
|
@ -46,7 +46,7 @@ impl IntoResponse for ServiceError {
|
||||||
|
|
||||||
fn into_response(self) -> axum::http::Response<Self::Body> {
|
fn into_response(self) -> axum::http::Response<Self::Body> {
|
||||||
let res = match self {
|
let res = match self {
|
||||||
ServiceError::Database(err) => ErrorResponse::new(StatusCode::INTERNAL_SERVER_ERROR, Some(err.to_string())),
|
ServiceError::Database(err) => get_oracle_error_response(err),
|
||||||
ServiceError::ErrorResponse(code, reason) => ErrorResponse::new(code, reason),
|
ServiceError::ErrorResponse(code, reason) => ErrorResponse::new(code, reason),
|
||||||
};
|
};
|
||||||
let status = res.status;
|
let status = res.status;
|
||||||
|
@ -62,4 +62,18 @@ impl ErrorResponse {
|
||||||
error: message.unwrap_or_else(|| reason.to_string()),
|
error: message.unwrap_or_else(|| reason.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_oracle_error_response(error: sibyl::Error) -> ErrorResponse {
|
||||||
|
match error {
|
||||||
|
sibyl::Error::Interface(_) => ErrorResponse::new(StatusCode::INTERNAL_SERVER_ERROR, None),
|
||||||
|
sibyl::Error::Oracle(code, message) => {
|
||||||
|
if code == 1 || code == 2291 || code == 20111 {
|
||||||
|
ErrorResponse::new(StatusCode::CONFLICT, Some(message))
|
||||||
|
} else {
|
||||||
|
ErrorResponse::new(StatusCode::INTERNAL_SERVER_ERROR, Some(message))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sibyl::Error::JoinError(_) => ErrorResponse::new(StatusCode::INTERNAL_SERVER_ERROR, None),
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue