{"_id":"standard-error","_rev":"11-baa26f2aa42649ce4be99891b5f47c0c","name":"standard-error","description":"Tiny library that simplifies subclassing and inheriting from Error while keeping the correct name and stack. Also supports constructing from an object of properties. Saves you from boilerplate.","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"standard-error","version":"1.0.0","description":"Tiny library that simplifies subclassing and inheriting from Error while keeping the correct name and stack. Also supports constructing from an object of properties. Saves you from boilerplate.","keywords":["error","exception"],"homepage":"https://github.com/moll/js-standard-error","bugs":{"url":"https://github.com/moll/js-standard-error/issues"},"author":{"name":"Andri Möll","email":"andri@dot.ee","url":"http://themoll.com"},"repository":{"type":"git","url":"git://github.com/moll/js-standard-error.git"},"licenses":[{"type":"LAGPL","url":"https://github.com/moll/js-standard-error/blob/master/LICENSE"}],"main":"index.js","scripts":{"test":"make test"},"devDependencies":{"mocha":">= 1.18.0 < 2","must":"< 1"},"_id":"standard-error@1.0.0","dist":{"shasum":"38671a79760f7fae5c09833974d0b528c204289b","tarball":"https://registry.npmjs.org/standard-error/-/standard-error-1.0.0.tgz","integrity":"sha512-9+tV6ku9GbXBlOfuxcoZfcKYcQ8V4I8H/5ZVw2QMEn2pH5x+9XYjFX3rwAydiwnVbrkmSNbyb7TI+uPyf7PThA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHP9vD6tv8pykUYvIuWud/d0Q/zcCbwE+aetYUPTQlHmAiEA9GGAd8moumR7IQz3IAoJ0layHs65BNRzjIqF3d8MbT8="}]},"_from":".","_npmVersion":"1.4.6","_npmUser":{"name":"moll","email":"andri@dot.ee"},"maintainers":[{"name":"moll","email":"andri@dot.ee"}]},"1.1.0":{"name":"standard-error","version":"1.1.0","description":"Tiny library that simplifies subclassing and inheriting from Error while keeping the correct name and stack. Also supports constructing from an object of properties. Saves you from boilerplate.","keywords":["error","exception"],"homepage":"https://github.com/moll/js-standard-error","bugs":{"url":"https://github.com/moll/js-standard-error/issues"},"author":{"name":"Andri Möll","email":"andri@dot.ee","url":"http://themoll.com"},"repository":{"type":"git","url":"git://github.com/moll/js-standard-error.git"},"licenses":[{"type":"LAGPL","url":"https://github.com/moll/js-standard-error/blob/master/LICENSE"}],"main":"index.js","scripts":{},"devDependencies":{"mocha":">= 1.18.0 < 2","must":"< 1"},"gitHead":"fbee48fed75bd8e039b5a3f3a7e45f62b6d3b28d","_id":"standard-error@1.1.0","_shasum":"23e5168fa1c0820189e5812701a79058510d0d34","_from":".","_npmVersion":"1.4.13","_npmUser":{"name":"moll","email":"andri@dot.ee"},"maintainers":[{"name":"moll","email":"andri@dot.ee"}],"dist":{"shasum":"23e5168fa1c0820189e5812701a79058510d0d34","tarball":"https://registry.npmjs.org/standard-error/-/standard-error-1.1.0.tgz","integrity":"sha512-4v7qzU7oLJfMI5EltUSHCaaOd65J6S4BqKRWgzMi4EYaE5fvNabPxmAPGdxpGXqrcWjhDGI/H09CIdEuUOUeXg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCID9XygPr6PmlO69VzJ3hZdTWlq2+KELh8xQdsPOSueGmAiEA9pRtraLa/OO15+OukIZcFGMgTX4m0BDPn2kkMMPNEAk="}]}}},"readme":"StandardError.js\n================\n[![NPM version][npm-badge]](http://badge.fury.io/js/standard-error)\n[npm-badge]: https://badge.fury.io/js/standard-error.png\n\nStandardError.js is a tiny JavaScript library that simplifies creating\nsubclasses of `Error` for **custom error classes** with the correct `name` and\n`stack` property. Saves you from writing a few lines of boilerplate.\n\n### Tour\n- Create **custom error classes** and add new behavior to them while keeping the\n  standard `Error` behavior in tact.\n- Add **extra properties** to the error by just passing in an object.\n- StandardError.js sets the error's **stack trace correctly**, even if your\n  error class **subclasses/inherits** from StandardError.  \n  Just inheriting from `Error` with `Object.create` breaks the stack trace.\n- Every `StandardError` instance is also an instance of `Error`.\n- Serializes all expected properties when passing it to `JSON.stringify`.  \n  Did you know that the default `Error` object serializes to an empty object\n  (`{}`)?\n- Works both in Node.js and browsers and sets the stack trace via\n  `Error.captureStackTrace` where available.\n\n\nInstalling\n----------\n```\nnpm install standard-error\n```\n\n\nUsing\n-----\nJust require StandardError.js and either use it directly or inherit from it for\nyour custom error class.\n\n### Throwing StandardError\nLike `Error`, `StandardError` takes a message argument, but in addition to that,\nyou may give it an object with other properties to be set:\n\n```javascript\nvar StandardError = require(\"standard-error\")\nthrow new StandardError(\"Not Found\", {code: 404})\n```\n\nThe thrown instance of `StandardError` will then have both the `message` and the\n`code` property.  \nIt'll also also have a `name` property set to `\"StandardError\"`.\n\nYou can skip the explicit `message` argument and give everything as an\nobject of properties:\n\n```javascript\nnew StandardError({message: \"Not Found\", code: 404})\n```\n\n**Note**: All properties besides `stack` will be enumerable for easier\nserialization with `JSON.stringify`. That includes the `name` property which\nwill be set from the constructor's name (defaults to `\"StandardError\"`).\n\n### Subclassing and inheriting from StandardError\nThe real benefit of StandardError.js comes from subclassing it to create new\nerror classes and adding custom behavior to them.\n\nLet's create an `HttpError` that we can instantiate with the HTTP status code\n(`new HttpError(404)`) and have it set the message automatically based on that:\n\n```javascript\nvar Http = require(\"http\")\nvar StandardError = require(\"standard-error\")\n\nfunction HttpError(code, msg) {\n  StandardError.call(this, msg || Http.STATUS_CODES[code], {code: code})\n}\n\nHttpError.prototype = Object.create(StandardError.prototype, {\n  constructor: {value: HttpError, configurable: true, writable: true}\n})\n```\n\n**Note** that you must set the `constructor` property like in the above\nexample. First, that's the proper way to subclass in JavaScript and second,\nStandardError.js depends on that to know which functions to skip in the stack\ntrace.\n\n#### Name\n\nStandardError.js finds out the name (`err.name`) of your subclassed error from\nits constructor function. However, if you minify your code, you can also set or\nchange it explicitly:\n\n```javascript\nChildError.prototype.name = \"FallacyError\"\n```\n\n### Adding behavior to your subclass of StandardError\n\nNow that you've inherited, you can, for example, customize stringifying by\noverwriting `toString` on your subclass.  To get `new HttpError(404)` to print\nitself as `404 Not Found`:\n\n```javascript\nHttpError.prototype.toString = function() {\n  return this.code + \" \" + this.message\n}\n```\n\nLicense\n-------\nStandardError.js is released under a *Lesser GNU Affero General Public License*, which\nin summary means:\n\n- You **can** use this program for **no cost**.\n- You **can** use this program for **both personal and commercial reasons**.\n- You **do not have to share your own program's code** which uses this program.\n- You **have to share modifications** (e.g. bug-fixes) you've made to this\n  program.\n\nFor more convoluted language, see the `LICENSE` file.\n\n\nAbout\n-----\n**[Andri Möll](http://themoll.com)** typed this and the code.  \n[Monday Calendar](https://mondayapp.com) supported the engineering work.\n\nIf you find StandardError.js needs improving, please don't hesitate to type to\nme now at [andri@dot.ee][email] or [create an issue online][issues].\n\n[email]: mailto:andri@dot.ee\n[issues]: https://github.com/moll/js-standard-error/issues\n","maintainers":[{"name":"moll","email":"andri@dot.ee"}],"time":{"modified":"2022-06-26T23:44:28.310Z","created":"2014-05-01T12:28:38.793Z","1.0.0":"2014-05-01T12:28:38.793Z","1.1.0":"2014-06-15T22:00:54.234Z"},"homepage":"https://github.com/moll/js-standard-error","keywords":["error","exception"],"repository":{"type":"git","url":"git://github.com/moll/js-standard-error.git"},"author":{"name":"Andri Möll","email":"andri@dot.ee","url":"http://themoll.com"},"bugs":{"url":"https://github.com/moll/js-standard-error/issues"},"readmeFilename":"README.md","users":{"moll":true,"guumaster":true}}