0.0.3 • Published 5 years ago

aws-lambda-error-handler v0.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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
# ...