Parse errors in the Browser and Node. Made for Cabin.
npm install parse-err




> Parse errors to provide a consistent metadata object across Browser and Node environments. Made for [Cabin][].
* Install
* How does it work
* Usage
* Node
* VanillaJS
* Bundler
* Supported Platforms
* Contributors
* License
[npm][]:
``sh`
npm install parse-err
This package exports a function that accepts two arguments (err, props).
* req (Object) - an HTTP requestprops
* (Array) - a list of properties to cherry-pick from the error object parsed out of err (by default all properties are returned; even non-enumerable ones and ones on the prototype object)
This function iterates over the prototype of the error and the error itself to get all non-Function properties and returns these properties as an object.
Normally if you console.log(err) it will not show you all fields such as type, statusCode, or code (e.g. [if you're using Stripe][stripe-error]).
In our case, we wanted to store these properties in our logs with [Cabin][].
As of v1.0.0 it now parses err.errors Array too – which adds support for packages such as [maybe-combine-errors][] and [combine-errors][]. This is useful if you combine multiple errors into one Error object, and subsequently set a property of err.errors = errors where errors is an Array of the errors combined.
`js
const parseErr = require('parse-err');
const err = new Error('Oops!');
// just a random example
err.name = 'BeepBoop';
err.code = 100;
err.statusCode = 200;
console.error(parseErr(err));
`
`sh`
{ name: 'BeepBoop',
message: 'Oops!',
stack: 'BeepBoop: Oops!\n at Object.
code: 100,
statusCode: 200 }
`html`
If you are using [browserify][], [webpack][], [rollup][], or another bundler, then you can follow the same usage as Node above.
* Node: v6.x+
* Browsers (see .browserslistrc):
`sh`
npx browserslist
`sh``
and_chr 107
and_ff 106
and_qq 13.1
and_uc 13.4
android 107
chrome 107
chrome 106
chrome 105
edge 107
edge 106
edge 105
firefox 107
firefox 106
firefox 105
firefox 102
ios_saf 16.1
ios_saf 16.0
ios_saf 15.6
ios_saf 15.5
ios_saf 14.5-14.8
kaios 2.5
op_mini all
op_mob 72
opera 92
opera 91
safari 16.1
safari 16.0
safari 15.6
samsung 19.0
samsung 18.0
| Name | Website |
| -------------- | -------------------------- |
| Nick Baugh |
##
[npm]: https://www.npmjs.com/
[stripe-error]: https://github.com/stripe/stripe-node/blob/3c07d851cf897490d8b93dd4457dda0c4c8e667f/lib/Error.js#L33-L45
[cabin]: https://cabinjs.com
[maybe-combine-errors]: https://www.npmjs.com/package/maybe-combine-errors
[combine-errors]: https://www.npmjs.com/package/combine-errors
[browserify]: https://github.com/browserify/browserify
[webpack]: https://github.com/webpack/webpack
[rollup]: https://github.com/rollup/rollup