Skip to content

Commit 37dfe98

Browse files
committed
Simplify R404 handler
1 parent 59d8498 commit 37dfe98

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/router.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

33
use conduit::{Handler, HandlerResult, RequestExt};
4-
use conduit_router::{RequestParams, RouteBuilder};
4+
use conduit_router::{RequestParams, RouteBuilder, RouterError};
55

66
use crate::controllers::*;
77
use crate::util::errors::{std_error, AppError, NotFound};
@@ -173,12 +173,9 @@ pub struct R404(pub RouteBuilder);
173173
impl Handler for R404 {
174174
fn call(&self, req: &mut dyn RequestExt) -> HandlerResult {
175175
let R404(ref router) = *self;
176-
match router.recognize(&req.method(), req.path()) {
177-
Ok(m) => {
178-
req.mut_extensions().insert(m.params().clone());
179-
m.handler().call(req)
180-
}
181-
Err(..) => Ok(NotFound.into()),
176+
match router.call(req) {
177+
Err(e) if e.downcast_ref::<RouterError>().is_some() => Ok(NotFound.into()),
178+
other => other,
182179
}
183180
}
184181
}

0 commit comments

Comments
 (0)