sunng87 / handlebars-iron

Handlebars middleware for Iron web framework
MIT License
119 stars 20 forks source link

Template is not rendered in AfterMiddleware #50

Closed euclio closed 7 years ago

euclio commented 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".

sunng87 commented 7 years ago

hi @euclio , could you please confirm the ErrorHandler in the chain was before the HandlebarsEngine?

euclio commented 7 years ago

That was it! Thank you for the help 😄