1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

unify route not found handling

This commit is contained in:
Nikolay Kim
2017-12-11 16:26:51 -08:00
parent b1ae7f95cc
commit 007b7ce62f
3 changed files with 40 additions and 12 deletions

View File

@ -526,3 +526,27 @@ predicates match. i.e:
```rust,ignore
pred::All(vec![pred::Get(), pred::Header("content-type", "plain/text")])
```
## Changing the default Not Found response
If path pattern can not be found in routing table or resource can not find matching
route default resource is used. Default response is *NOT FOUND* response.
To override *NOT FOUND* resource use `Application::default_resource()` method.
This method accepts *configuration function* same as normal resource registration
with `Application::resource()` method.
``rust
# extern crate actix_web;
# extern crate http;
use actix_web::*;
use actix_web::httpcodes::*;
fn main() {
Application::new()
.default_resource(|r|
r.method(Method::GET).f(|req| HTTPNotFound);
r.route().p(pred::Not(pred::Get()).f(|req| HTTPMethodNotAllowed);
})
.finish();
}
```