aws-lambda-error-handler
v0.0.3
Published
AWS Lambda error handler
Downloads
4
Readme
aws-lambda-error-handler
Usage
/* testHandler.js */
import { withCatch, BaseError } from 'aws-lambda-error-handler'
class UserNameConflictError extends BaseError {
constructor() {
super('Username already exists')
this.statusCode = 400
}
}
export const fn = withCatch(
async (event, context) => {
throw new UserNameConflictError()
return {
statusCode: 200,
body: JSON.stringify({
message: 'ok'
})
}
}
)
# serverless.yml
# ...
functions:
test_handler:
handler: path/to/testHandler.fn
# ...