1.3.0 • Published 1 year ago

@banxware/simple-error v1.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Simple Errors

Description

Tired of creating the errors over and over again in different repos? Pissed of on how inconsistent they can be? Your problems are now over! With the super duper uper simple errors this problem is now solved.

Install

$ npm i @banxware/simple-error

Usage

const myHandler = (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
  try {
    // your busines logic goes here
    
  } catch(error) {
    toApiGatewayErrorResponse(error)
  }
}

The toApiGatewayErrorResponse function will convert all responses to a common response. If it is comming from axios it will convert with the correct status code and the message sent by the downstream service. If you are using simple-repository, 404s will be handled as well. Every non-handled error will be treated as a 500 - Internal Server Error.

Extending

In case you want to implement some custom internal errors, you have two options: 1. You can extend CustomError 2. You can extend BanxwareApiGatewayError

Both errors will be interpreted by the toApiGatewayErrorResponse. The difference is the second one will enforce the status code and it is more suitable for http/rest errors.

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago