mirror of
https://github.com/tokio-rs/axum.git
synced 2024-12-29 15:49:16 +01:00
Handle METHOD_NOT_ALLOWED
in 404 example (#131)
If a route existed but had no handler for the method, the code used in the 404 example wouldn't catch it.
This commit is contained in:
parent
d4ce90e2e6
commit
2be79168d8
1 changed files with 8 additions and 6 deletions
|
@ -39,12 +39,14 @@ async fn handler() -> response::Html<&'static str> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_404(response: Response<BoxBody>) -> Response<BoxBody> {
|
fn map_404(response: Response<BoxBody>) -> Response<BoxBody> {
|
||||||
if response.status() != StatusCode::NOT_FOUND {
|
if response.status() == StatusCode::NOT_FOUND
|
||||||
return response;
|
|| response.status() == StatusCode::METHOD_NOT_ALLOWED
|
||||||
|
{
|
||||||
|
return Response::builder()
|
||||||
|
.status(StatusCode::NOT_FOUND)
|
||||||
|
.body(box_body(Body::from("nothing to see here")))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
Response::builder()
|
response
|
||||||
.status(StatusCode::NOT_FOUND)
|
|
||||||
.body(box_body(Body::from("nothing to see here")))
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue