JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2752
  • Score
    100M100P100Q118586F
  • License MIT

Parse errors in the Browser and Node. Made for Cabin.

Package Exports

  • parse-err

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parse-err) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

parse-err

build status code coverage code style styled with prettier made with lass license

Parse errors to provide a consistent metadata object across Browser and Node environments. Made for Cabin.

Table of Contents

Install

npm:

npm install parse-err

yarn:

yarn add parse-err

How does it work

This package exports a function that accepts two arguments (err, props).

  • req (Object) - an HTTP request
  • props (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).

In our case, we wanted to store these properties in our logs with Cabin.

Usage

Node

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));
{ name: 'BeepBoop',
  message: 'Oops!',
  stack: 'BeepBoop: Oops!\n    at Object.<anonymous> (/Users/user/Projects/parse-err/test.js:3:13)\n    at Module._compile (module.js:652:30)\n    at Object.Module._extensions..js (module.js:663:10)\n    at Module.load (module.js:565:32)\n    at tryModuleLoad (module.js:505:12)\n    at Function.Module._load (module.js:497:3)\n    at Function.Module.runMain (module.js:693:10)\n    at startup (bootstrap_node.js:188:16)\n    at bootstrap_node.js:609:3',
  code: 100,
  statusCode: 200 }

VanillaJS

<script src="https://unpkg.com/parse-err"></script>
<script type="text/javascript">
  (function() {
    var err = new Error('Oops!');
    err.name = 'BeepBoop';
    err.statusCode = 500;
    console.error(parseErr(err));
  })();
</script>

Contributors

Name Website
Nick Baugh http://niftylettuce.com/

License

MIT © Nick Baugh