@banxware/simple-error
v1.3.0
Published
A simple repository for error handling.
Downloads
41
Maintainers
Keywords
Readme
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:
- You can extend CustomError
- 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.