@rnskv/terror
v1.0.10
Published
Simple and understandable custom error handling.
Downloads
10
Maintainers
Readme
Extended from common error, class TError allows create and cofigurate custom errors. Error's configuration allow using logging, user alert, debugging simple and fast.
Because i want unify work with errors. Make it simple and clean.
import { TErrorGroup } from '@rnskv/terror';
- Create errors white list;
- Create Errors Groups, using list from 1 step;
- Generate new errors in your code :).
const errorsList = {
PAGE_NOT_FOUND: {
message: 'Page not found :(', //Message for user
name: 'REQUEST_ERROR', //Name for logging
code: 404 //HTTP code
},
INTERNAL_SERVER_ERROR: {
message: 'Internal Server Error', //Message for user
name: 'RESPONSE_ERROR', //Name for logging
code: 500 //HTTP code
}
};
const params = {
type: 'SERVER_ERROR'
};
const ServerErrors = new TErrorGroup(params, errorsList)
try {
throw ServerErrors.create('PAGE_NOT_FOUND');
// Or
throw ServerErrors.create('INTERNAL_SERVER_ERROR');
} catch(error) {
console.log('Catch error:', error)
}
ServerErrors.setLogger(console.error);