Skip to content

Commit

Permalink
fix(example): return proper 404 for unmatched routes
Browse files Browse the repository at this point in the history
Relates to #60
  • Loading branch information
cburgdorf committed Aug 11, 2014
1 parent 0037d54 commit 37a851b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion examples/example_with_default_router.rs
Expand Up @@ -2,7 +2,8 @@ extern crate serialize;
extern crate nickel;
extern crate http;

use nickel::{ Nickel, Request, Response };
use http::status::{ NotFound };
use nickel::{ Nickel, Request, Response, ErrorWithStatusCode, Action, NickelError, IntoMiddleware };
use std::io::net::ip::Ipv4Addr;

fn main() {
Expand All @@ -23,5 +24,13 @@ fn main() {
// go to http://localhost:6767/foo to see this route in action
server.get("/foo", foo_handler);

//middleware to catch all non matched routes
fn catch_all (_request: &Request, _response: &mut Response) -> Result<Action, NickelError> {
Err(NickelError::new("File Not Found", ErrorWithStatusCode(NotFound)))
}

// middleware is optional and can be registered with `utilize`
server.utilize(IntoMiddleware::from_fn(catch_all));

server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}

0 comments on commit 37a851b

Please sign in to comment.