brinkbit-custom-errors
A super simple collection of custom errors for use in brinkbit modules
Install
npm i --save brinkbit-custom-errors
Overview
Exposes seven common custom errors based on http status codes:
- BadRequestError - 400
- AuthenticationError - 401
- PaymentError - 402
- AuthorizationError - 403
- NoResourceError - 404
- ConflictError - 409
- TooLargeError - 413
Usage
const customErrors = ;const requestError = // internal message for logging message: 'Missing required username field' // external message to forward to client description: 'Missing or invalid parameter' // error type code to forward to client type: customErrorstypeinvalid_request_error // a hash of properties and details details: username: customErrorsdetailsmissing_parameter ;
API
Includes constants for detail codes
customErrorsdetailsmissing_parametercustomErrorsdetailsinvalid_parametercustomErrorsdetailsconflicting_parametercustomErrorsdetailsmissing_resourcecustomErrorsdetailstoo_large
Includes constants for type codes
customErrorstypeauthentication_errorcustomErrorstypeinvalid_request_errorcustomErrorstypepayment_errorcustomErrorstyperate_limit_errorcustomErrorstypeinternal_error
Default types for http status codes are exposed and can be overridden:
customErrorstypesDEFAULTS400 =customErrorstypesDEFAULTS403 =customErrorstypesDEFAULTS404 =customErrorstypesDEFAULTS409 =customErrorstypesDEFAULTS413 = typesinvalid_request_error;customErrorstypesDEFAULTS401 = typesauthentication_error;customErrorstypesDEFAULTS402 = typespayment_error;customErrorstypesDEFAULTS500 = typesinternal_error;