Closed euclio closed 7 years ago
I'm trying to implement a custom 404 handler that renders a handlebars template. I have the following code:
struct ErrorHandler; impl AfterMiddleware for ErrorHandler { fn catch(&self, _: &mut Request, err: IronError) -> IronResult<Response> { if let Some(_) = err.error.downcast::<NoRoute>() { Ok(Response::with((status::NotFound, Template::new("not_found", ())))); } else { Err(err) } } }
I have made sure that the template is registered (my other templates work correctly), and that the middleware is linked. However, there is no body in the response. "Not found" is returned in the body if I replace the Template::new with "Not found".
Template::new
"Not found"
hi @euclio , could you please confirm the ErrorHandler in the chain was before the HandlebarsEngine?
ErrorHandler
HandlebarsEngine
That was it! Thank you for the help 😄
I'm trying to implement a custom 404 handler that renders a handlebars template. I have the following code:
I have made sure that the template is registered (my other templates work correctly), and that the middleware is linked. However, there is no body in the response. "Not found" is returned in the body if I replace the
Template::new
with"Not found"
.