@specialblend/pretty-error
v0.0.8
Published
Readable, property-bearing custom ES6 errors for Node.js
Downloads
14
Readme
pretty-error
Readable, property-bearing custom ES6 errors for Node.js
install
npm install @specialblend/pretty-error
Example
import PrettyError from '@specialblend/pretty-error';
class JSONError extends PrettyError {}
export const parseJSON = str => {
try {
return JSON.parse(str);
} catch (err) {
throw new JSONError('Invalid JSON!', { str })
}
}
Output:
JSONError: Invalid JSON!
{
str: '{this;is-not.valid/json'
}
at parseJSON (/Users/specialblend/workspace/pretty-error/examples/parse-json.js:11:15)
at Object.parseJSON (/Users/specialblend/workspace/pretty-error/examples/parse-json.js:15:1)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Module._compile (/Users/specialblend/workspace/pretty-error/node_modules/pirates/lib/index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Object.newLoader [as .js] (/Users/specialblend/workspace/pretty-error/node_modules/pirates/lib/index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)