npm-middlewares
A collection of middyJS custom middlewares for lambda functions
Installation
npm install --save npm-middlewares
Middlewares documentation
Available middlewares
httpErrorHandler
Automatically handles uncaught errors that are created with
http-errors
and creates a proper HTTP response
for them (using the message and the status code provided by the error object).
Supports ajv
validation errors by
looking for errors with the error message: Event object failed validation
.
Will call the function ajv.errorsText
passing in the error.details
.
It should be set as the last error handler.
Sample usage
const middy = const httpErrorHandler = const handler = handler // when Lambda runs the handler...
httpResponseHandler
Automatically handles returned objects from the callback
or returned when using an async
function and creates a proper HTTP response
for them (using the object as the response body and a 200 status code).
Sample usage
const middy = const httpResponseHandler = // When using an async/await syntax const handler = // Or when using a non async function, use the callback const handler = handler // when Lambda runs the handler...