Kosa means "error" in Swahili.
This package introduces a managed scoped Error class. The Error Object which is instanciated doesn't have stacktrace on purpose. It is designed to be and stay simple !!!
Here is an exemple:
{statusCode: 400,message: 'USER_REGISTER_BAD_REQUEST',// Comes from scope & statusmeta: {// Optional - contextual informationerror: '...',context: '...',details: {
...
},validations: [{field: 'email',message: 'missing tld'},{field: 'firstname',message: 'should start with a capital'}]...}}Here are the constructor arguments:
scoperequired stringstatusCodeoptional numbermetaoptional object with contextual information you might want to provide about the error
Here is how you use it in your code.
constKosa=require('@webinmove/kosa');if(!user){thrownewKosa('USER',404);}if(vadlidationErrors.length>0){thrownewKosa('USER_REGISTER',400,vadlidationErrors);}- 400 BAD_REQUEST
- 401 UNAUTHORIZED
- 403 FORBIDDEN
- 404 NOT_FOUND
- 405 METHOD_NOT_ALLOWED
- 408 REQUEST_TIMEOUT
- 409 CONFLICT
- 415 UNSUPPORTED_MEDIA_TYPE
- 418 TEAPOT
- 429 TOO_MANY_REQUESTS
- 500 INTERNAL_SERVER_ERROR (default)