aug-error
v0.1.0
Published
Augmented errors
Downloads
1
Readme
aug-error
Augmented errors
Set up
npm install --save aug-error # for npm
yarn add aug-error # for yarn
Usage
const path = require('path');
const augError = require('aug-error');
augError.registerMessagesFromDirSync(path.resolve(__dirname, 'errors'));
doSomething((err) => {
if (err) {
throw augError.augment(new Error(), augError.codes.SOME_CODE, {
somethingWentWrong: 'details about what went wrong',
}, err);
}
});
augError.augment(err: Error, code: string, details?: Object, causedBy?: Error)
Returns an Error
object, that has been augmented with code
, causedBy
, and details
.
In fact the passed in empty Error
object is returned, having simply been augmented with this.
The reason for passing in the Error
object rather than having aug-error
generate one internally,
is so that the stacktrace of the error is more meaningful - that is, remains unpolluted by any part
of the aug-error
library, and entirely part of the context from within it is called.
augError.registerMessagesFromDirSync(dir: string, langs?: string[])
Loads errors in different languages from the specified dir
. A default.json
is always loaded,
and any additional languages specified in langs
will be loaded too. The contents of these files
are expected to be simple flat objects where the keys are the error codes, and the values are the
display messages. All the language files should have a matching set of error codes.
Author
Licence
GPL-3.0