chore(server): send error message in the json `error` field in response
Previously it returned enum in json in `error_message` filed.
This commit is contained in:
parent
cca7dd3efd
commit
5f920d66cf
|
@ -7,9 +7,9 @@ use super::{AuthError, FsError};
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Error)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Error)]
|
||||||
#[serde(tag = "error", content = "error_message", rename_all = "kebab-case")]
|
#[serde(tag = "error", content = "error_message", rename_all = "kebab-case")]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("auth error - {0}")]
|
#[error("auth error: {0}")]
|
||||||
AuthError(#[from] AuthError),
|
AuthError(#[from] AuthError),
|
||||||
#[error("fs error - {0}")]
|
#[error("fs error: {0}")]
|
||||||
FsError(#[from] FsError),
|
FsError(#[from] FsError),
|
||||||
#[error("too may requests, please slow down")]
|
#[error("too may requests, please slow down")]
|
||||||
TooManyRequests,
|
TooManyRequests,
|
||||||
|
@ -21,10 +21,22 @@ pub enum Error {
|
||||||
JsonSyntaxError,
|
JsonSyntaxError,
|
||||||
#[error("failed to extract the request body")]
|
#[error("failed to extract the request body")]
|
||||||
BytesRejection,
|
BytesRejection,
|
||||||
#[error("other error - {0}")]
|
#[error("other error: {0}")]
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
enum ResponseError {
|
||||||
|
Error(String)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error {
|
||||||
|
fn into_response(self) -> ResponseError {
|
||||||
|
ResponseError::Error(self.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "axum")]
|
#[cfg(feature = "axum")]
|
||||||
impl axum::response::IntoResponse for Error {
|
impl axum::response::IntoResponse for Error {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
@ -51,7 +63,7 @@ impl axum::response::IntoResponse for Error {
|
||||||
_ => StatusCode::BAD_REQUEST,
|
_ => StatusCode::BAD_REQUEST,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut response = axum::Json(self).into_response();
|
let mut response = axum::Json(self.into_response()).into_response();
|
||||||
*response.status_mut() = status;
|
*response.status_mut() = status;
|
||||||
|
|
||||||
response
|
response
|
||||||
|
|
Loading…
Reference in New Issue