Passing the middleware stack to the error handler