diff --git a/src/error.rs b/src/error.rs index 214615e..f0613c0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -46,7 +46,7 @@ impl IntoResponse for ServiceError { fn into_response(self) -> axum::http::Response { 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), }; let status = res.status; @@ -62,4 +62,18 @@ impl ErrorResponse { 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), + } } \ No newline at end of file