add test + json errors
This commit is contained in:
+37
-11
@@ -15,6 +15,12 @@ pub enum AppError {
|
||||
#[error("WebHook sig header is invalid")]
|
||||
WebHookSigHeaderInvalidErr,
|
||||
|
||||
#[error("Missing required field: {0}")]
|
||||
MissingField(String),
|
||||
|
||||
#[error("Wrong type for field: {0}")]
|
||||
WrongFieldType(String),
|
||||
|
||||
#[error(transparent)]
|
||||
Other(#[from] anyhow::Error),
|
||||
}
|
||||
@@ -22,19 +28,39 @@ pub enum AppError {
|
||||
impl IntoResponse for AppError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
match self {
|
||||
AppError::MalformedJsonErr => (StatusCode::BAD_REQUEST, "Malformed Json"),
|
||||
AppError::MalformedJsonErr => {
|
||||
(StatusCode::BAD_REQUEST, "Malformed Json".to_string()).into_response()
|
||||
}
|
||||
AppError::BadJsonStructErr => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
"Json not contains mandatory fields",
|
||||
),
|
||||
AppError::WebHookSigHeaderNotFoundErr => {
|
||||
(StatusCode::BAD_REQUEST, "WebHook sig header not found")
|
||||
}
|
||||
AppError::WebHookSigHeaderInvalidErr => {
|
||||
(StatusCode::BAD_REQUEST, "WebHook sig header is invalid")
|
||||
}
|
||||
AppError::Other(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Internal server error"),
|
||||
"Json not contains mandatory fields".to_string(),
|
||||
)
|
||||
.into_response(),
|
||||
AppError::WebHookSigHeaderNotFoundErr => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
"WebHook sig header not found".to_string(),
|
||||
)
|
||||
.into_response(),
|
||||
AppError::WebHookSigHeaderInvalidErr => (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
"WebHook sig header is invalid".to_string(),
|
||||
)
|
||||
.into_response(),
|
||||
AppError::MissingField(ref field) => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
format!("Missing required field: {}", field),
|
||||
)
|
||||
.into_response(),
|
||||
AppError::WrongFieldType(ref field) => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
format!("Wrong type for field: {}", field),
|
||||
)
|
||||
.into_response(),
|
||||
AppError::Other(_) => (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Internal server error".to_string(),
|
||||
)
|
||||
.into_response(),
|
||||
}
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user