Skip to content

Commit

Permalink
reorder error handlers (#5001)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Masurel <[email protected]>
  • Loading branch information
trinity-1686a and fulmicoton authored May 17, 2024
1 parent fdde733 commit 2da14a1
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions quickwit/quickwit-serve/src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,6 @@ fn get_status_with_error(rejection: Rejection) -> RestApiError {
status_code: StatusCode::UNSUPPORTED_MEDIA_TYPE,
message: error.to_string(),
}
} else if rejection.is_not_found() {
RestApiError {
status_code: StatusCode::NOT_FOUND,
message: "Route not found".to_string(),
}
} else if let Some(error) = rejection.find::<serde_qs::Error>() {
RestApiError {
status_code: StatusCode::BAD_REQUEST,
Expand All @@ -291,12 +286,6 @@ fn get_status_with_error(rejection: Rejection) -> RestApiError {
status_code: StatusCode::BAD_REQUEST,
message: error.0.to_string(),
}
} else if let Some(error) = rejection.find::<InvalidArgument>() {
// Happens when the url path or request body contains invalid argument(s).
RestApiError {
status_code: StatusCode::BAD_REQUEST,
message: error.0.to_string(),
}
} else if let Some(error) = rejection.find::<warp::filters::body::BodyDeserializeError>() {
// Happens when the request body could not be deserialized correctly.
RestApiError {
Expand Down Expand Up @@ -338,11 +327,6 @@ fn get_status_with_error(rejection: Rejection) -> RestApiError {
status_code: StatusCode::BAD_REQUEST,
message: error.to_string(),
}
} else if let Some(error) = rejection.find::<warp::reject::MethodNotAllowed>() {
RestApiError {
status_code: StatusCode::METHOD_NOT_ALLOWED,
message: error.to_string(),
}
} else if let Some(error) = rejection.find::<warp::reject::PayloadTooLarge>() {
RestApiError {
status_code: StatusCode::PAYLOAD_TOO_LARGE,
Expand All @@ -353,6 +337,22 @@ fn get_status_with_error(rejection: Rejection) -> RestApiError {
status_code: StatusCode::TOO_MANY_REQUESTS,
message: err.to_string(),
}
} else if let Some(error) = rejection.find::<InvalidArgument>() {
// Happens when the url path or request body contains invalid argument(s).
RestApiError {
status_code: StatusCode::BAD_REQUEST,
message: error.0.to_string(),
}
} else if let Some(error) = rejection.find::<warp::reject::MethodNotAllowed>() {
RestApiError {
status_code: StatusCode::METHOD_NOT_ALLOWED,
message: error.to_string(),
}
} else if rejection.is_not_found() {
RestApiError {
status_code: StatusCode::NOT_FOUND,
message: "Route not found".to_string(),
}
} else {
error!("REST server error: {:?}", rejection);
RestApiError {
Expand Down

0 comments on commit 2da14a1

Please sign in to comment.