You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The docs suggest that we should add the error handler after all middleware, but this approach fails as if the validation middleware throws an error, the next middleware is not even attached.
What the docs suggest?
// Let's "middyfy" our handler, then we will be able to attach middlewares to it
const handler = middy(baseHandler)
.use(jsonBodyParser()) // parses the request body when it's a JSON and converts it to an object
.use(validator({inputSchema})) // validates the input
.use(httpErrorHandler()) // handles common http errors and returns proper responses
module.exports = { handler }
What it should suggest?
// Let's "middyfy" our handler, then we will be able to attach middlewares to it
const handler = middy(baseHandler)
.use(httpErrorHandler()) // handles common http errors and returns proper responses
.use(jsonBodyParser()) // parses the request body when it's a JSON and converts it to an object
.use(validator({inputSchema})) // validates the input
module.exports = { handler }
The httpErrorHandler should be the first middleware to be attached.
The text was updated successfully, but these errors were encountered:
Thanks for reporting. This is a very simple example and doesn't have complete error handling (See #720). Typically httpErrorHandler at the end to catch any errors thrown by any after middlewares. Improving how error handing works is planned for the next version of middy. I've tagged this for review when we tackle this.
The docs suggest that we should add the error handler after all middleware, but this approach fails as if the validation middleware throws an error, the next middleware is not even attached.
What the docs suggest?
What it should suggest?
The
httpErrorHandler
should be the first middleware to be attached.The text was updated successfully, but these errors were encountered: