{"_id":"custom-error-generator","_rev":"21-bf0362e97cb3110e3d5e84aada063f4b","name":"custom-error-generator","description":"Custom errors and exceptions in Node.js","dist-tags":{"latest":"7.0.0"},"versions":{"2.0.0":{"name":"custom-error-generator","version":"2.0.0","description":"Custom errors and exceptions in Node.js, done right","main":"index.js","scripts":{"test":"make test"},"author":{"name":"Jesse Proulx","email":"github@jproulx.net"},"license":"ISC","devDependencies":{"mocha":"","should":""},"repository":{"type":"git","url":"https://github.com/jproulx/node-custom-error.git"},"keywords":["error","errors"],"bugs":{"url":"https://github.com/jproulx/node-custom-error/issues"},"homepage":"https://github.com/jproulx/node-custom-error","_id":"custom-error-generator@2.0.0","dist":{"shasum":"8c2dcf2897472931735e6b047069ec0930bcc70e","tarball":"https://registry.npmjs.org/custom-error-generator/-/custom-error-generator-2.0.0.tgz","integrity":"sha512-RDroi3GIBa7f619uf0K9IwaPIxL0N5jeRyn9rzInxxNyha83cAzyHm2SwvvLqHIS+zx7yDPTYDmLA0DoYipsog==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDHiiiNyIC3Uj09OaKM/a85+PUxnrwswpHdBBBRpaZqSAiEAxznnKHGBmyzVD6qFfj+zzAhCj2t4gZ0qbNR3SgaE6ic="}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"jproulx","email":"github@jproulx.net"},"maintainers":[{"name":"jproulx","email":"github@jproulx.net"}]},"3.0.0":{"name":"custom-error-generator","version":"3.0.0","description":"Custom errors and exceptions in Node.js, done right","main":"index.js","scripts":{"test":"make test"},"author":{"name":"Jesse Proulx","email":"github@jproulx.net"},"license":"ISC","devDependencies":{"mocha":"","should":""},"repository":{"type":"git","url":"https://github.com/jproulx/node-custom-error.git"},"keywords":["error","errors"],"bugs":{"url":"https://github.com/jproulx/node-custom-error/issues"},"homepage":"https://github.com/jproulx/node-custom-error","_id":"custom-error-generator@3.0.0","dist":{"shasum":"2d795bf9be4a12e18343055b3119e98439724586","tarball":"https://registry.npmjs.org/custom-error-generator/-/custom-error-generator-3.0.0.tgz","integrity":"sha512-4GgurrlFd9Pk9Dl1L1A56D3FX1ha55aMqAW3Sv7z9YgSTCJRYrVNBx4rKsFLpDfZWUT3pL6PLwe8WEIFBGnogw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAIXlFOSrkvYdLzrotpDG2Kcz5qks0NFl8sN2tmBNSdzAiBLeq9XKBWmyJBOFAmzDFK8mg2bq4aIW+4+3x4fTVpzTQ=="}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"jproulx","email":"github@jproulx.net"},"maintainers":[{"name":"jproulx","email":"github@jproulx.net"}]},"5.0.0":{"name":"custom-error-generator","version":"5.0.0","description":"Custom errors and exceptions in Node.js, done right","main":"error.js","scripts":{"test":"make test"},"author":{"name":"Jesse Proulx","email":"github@jproulx.net"},"license":"ISC","devDependencies":{"mocha":"","should":""},"repository":{"type":"git","url":"https://github.com/jproulx/node-custom-error.git"},"keywords":["error","errors"],"bugs":{"url":"https://github.com/jproulx/node-custom-error/issues"},"homepage":"https://github.com/jproulx/node-custom-error","_id":"custom-error-generator@5.0.0","dist":{"shasum":"d9c9fa1e95e6ceb8df4e09e7b08db90f54857838","tarball":"https://registry.npmjs.org/custom-error-generator/-/custom-error-generator-5.0.0.tgz","integrity":"sha512-9nno8mSJUDjF2GAhEA8V1J5KrIPaCd9xOAZ3IZlalO00BLXY106zSR6mARP36ONfDW2EF6hJMnuK1QYaiEO+qg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID2sNBAcAWlqtuEixgZ4zIhv97hFwW/8N2B10geIdcnWAiA5HPQBn+16z8R9xHayclL2UnnjcNsWM0BOtyfeW2tyUQ=="}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"jproulx","email":"github@jproulx.net"},"maintainers":[{"name":"jproulx","email":"github@jproulx.net"}]},"6.0.0":{"name":"custom-error-generator","version":"6.0.0","description":"Custom errors and exceptions in Node.js","main":"error.js","scripts":{"test":"make test"},"engines":["node >=0.6.0"],"config":{"blanket":{"pattern":"/error.js","data-cover-never":"node_modules"}},"author":{"name":"Jesse Proulx","email":"github@jproulx.net"},"license":"ISC","devDependencies":{"mocha":"","should":"","blanket":""},"repository":{"type":"git","url":"https://github.com/jproulx/node-custom-error.git"},"keywords":["error","errors","error factory","custom error"],"bugs":{"url":"https://github.com/jproulx/node-custom-error/issues"},"homepage":"https://github.com/jproulx/node-custom-error","_id":"custom-error-generator@6.0.0","dist":{"shasum":"997b7b71f087435d8130e2bf6f4f5efd97626687","tarball":"https://registry.npmjs.org/custom-error-generator/-/custom-error-generator-6.0.0.tgz","integrity":"sha512-95nbPGVnnP+IBxXSeXTo9FHihlYa2Ojrwm7cWv/ynU0KsD9X3wlr44hBlu2q+bbcTGd6+rUMmbkHkh6Sz47jYA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGhzoYV4HrvuDuAySHt56xzgMjbL01Sr5aIxDRkIZ72yAiBIL4HcudOwAl2ExjTp/9iWQDI9/WoR54wmPR5CtNNJ5g=="}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"jproulx","email":"github@jproulx.net"},"maintainers":[{"name":"jproulx","email":"github@jproulx.net"}]},"6.1.0":{"name":"custom-error-generator","version":"6.1.0","description":"Custom errors and exceptions in Node.js","main":"error.js","scripts":{"test":"make test"},"engines":["node >=0.6.0"],"config":{"blanket":{"pattern":"/error.js","data-cover-never":"node_modules"}},"author":{"name":"Jesse Proulx","email":"github@jproulx.net"},"license":"ISC","devDependencies":{"mocha":"","should":"","blanket":"","mocha-lcov-reporter":""},"repository":{"type":"git","url":"https://github.com/jproulx/node-custom-error.git"},"keywords":["error","errors","error factory","custom error"],"bugs":{"url":"https://github.com/jproulx/node-custom-error/issues"},"homepage":"https://github.com/jproulx/node-custom-error","_id":"custom-error-generator@6.1.0","dist":{"shasum":"92a45af75004b5f65d8b1e9efd37860a675bd1c6","tarball":"https://registry.npmjs.org/custom-error-generator/-/custom-error-generator-6.1.0.tgz","integrity":"sha512-6ry8OXIBgJyEneiqkiUdpzV/3nYxSp1fLe1CYr/cGWCsmLNqBuitCpzXBYZDIieGF+Twd4iROApOM4/qICDs+w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDPXx6Mjma+QMo9l2wqHShBR6wU9/hXPrfHGXGxLdWI4gIhAP+8P5O4kB+IR2xh7snz0LQ+ox9rjQFVFPv8+eWAa1il"}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"jproulx","email":"github@jproulx.net"},"maintainers":[{"name":"jproulx","email":"github@jproulx.net"}]},"7.0.0":{"name":"custom-error-generator","version":"7.0.0","description":"Custom errors and exceptions in Node.js","main":"error.js","scripts":{"test":"make test"},"engines":["node >=0.6.0"],"config":{"blanket":{"pattern":"/error.js","data-cover-never":"node_modules"},"travis-cov":{"threshold":80}},"author":{"name":"Jesse Proulx","email":"github@jproulx.net"},"license":"ISC","devDependencies":{"mocha":"","should":"","blanket":"","mocha-lcov-reporter":"","jshint":"","travis-cov":"","codeclimate-test-reporter":"","coveralls":""},"repository":{"type":"git","url":"https://github.com/jproulx/node-custom-error.git"},"keywords":["error","errors","error factory","custom error"],"bugs":{"url":"https://github.com/jproulx/node-custom-error/issues"},"homepage":"https://github.com/jproulx/node-custom-error","_id":"custom-error-generator@7.0.0","dist":{"shasum":"b16f8d09636327f69ae80a1043766f30f4506408","tarball":"https://registry.npmjs.org/custom-error-generator/-/custom-error-generator-7.0.0.tgz","integrity":"sha512-/sR1A6avsI0IOeeOThWlnZqnx5/aoBsI2FznAmFiMC5loQissvItrVAkkc+AJEhBb/FC9nkVkjH2NyqYQkzNHw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGkgfCkS5mQBoHJPazBfjVnpTlgKK4S9stN3q4GMX9K6AiEAqp0CYccFx1rlPj+4gFRSP12DfGWm6AhagUCNBAZtPmw="}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"jproulx","email":"github@jproulx.net"},"maintainers":[{"name":"jproulx","email":"github@jproulx.net"}]}},"readme":"node-custom-error\n===================\n[![Build Status](https://travis-ci.org/jproulx/node-custom-error.svg?branch=master)](https://travis-ci.org/jproulx/node-custom-error)[![devDependency Status](https://david-dm.org/jproulx/node-custom-error/dev-status.svg)](https://david-dm.org/jproulx/node-custom-error#info=devDependencies)[![Code Climate](https://codeclimate.com/github/jproulx/node-custom-error.png)](https://codeclimate.com/github/jproulx/node-custom-error)[![CodeClimate](https://codeclimate.com/github/jproulx/node-custom-error/coverage.png)](https://codeclimate.com/github/jproulx/node-custom-error)[![Coverage Status](https://coveralls.io/repos/jproulx/node-custom-error/badge.png?branch=master)](https://coveralls.io/r/jproulx/node-custom-error?branch=master)\n\n[![NPM](https://nodei.co/npm/custom-error-generator.png)](https://nodei.co/npm/custom-error-generator/)\n\nCustom errors and exceptions in Node.js\n\n## Install\n\n```bash\n$ npm install custom-error-generator --save\n```\n\n## Usage\n\n```javascript\nvar createCustomError = require('custom-error-generator');\nvar ValidationError = createCustomError('ValidationError', { 'required', 'Missing parameter x' }, TypeError);\nvar HTTPError = createCustomError('HTTPError', { 'code' : 500, 'status' : 'Server Error' });\n\nthrow new ValidationError('Required');\n```\n\nThe generator function supports the following parameters:\n\n* `name` {String} (required) - A custom name for this error type, which is printed when logging and in stack traces\n\n* `data` {Object} (optional) - Additional properties to attach to the error, in key=value pairs or as object descriptors\n\n* `Constructor` {Function} (optional) - A function to inherit from. Allows for additional methods and properties to be defined on your custom errors\n\nThe errors created by the generated functions are identical to built-in Error objects, with additional features such as:\n\nCustom properties can be attached and accessed at run time:\n```javascript\nvar error = new HTTPError('Uh oh');\nconsole.log(error.code, error.status); // prints 500 Server Error\n```\n\n## Formatting\n\nSimilar to `console.log`, the custom error message will be formatted from all available string and number arguments, using `util.format`:\n```javascript\nvar error = new ValidationError('%s: %s', 'Missing Field', 'name');\nconsole.log(error); // prints ValidationError: Missing Field: name\n```\n\n## Wrapped errors\n\nOther error objects can be passed in as arguments, which augment the original error stack trace with their own stack traces:\n```javascript\nvar error = new ValidationError('Missing field');\nvar serverError = new HTTPError('Something went wrong', error);\nconsole.log(serverError.stack);\n```\noutputs:\n```bash\nHTTPError: Something went wrong\n    at Context.<anonymous> (/Projects/node-custom-error/test.js:19:24)\n    at callFn (/Projects/node-custom-error/node_modules/mocha/lib/runnable.js:223:21)\n    at Hook.Runnable.run (/Projects/node-custom-error/node_modules/mocha/lib/runnable.js:216:7)\n    at next (/Projects/node-custom-error/node_modules/mocha/lib/runner.js:259:10)\n    at Object._onImmediate (/Projects/node-custom-error/node_modules/mocha/lib/runner.js:276:5)\n    at processImmediate [as _immediateCallback] (timers.js:330:15)\nValidationError: Missing field\n    at Context.<anonymous> (/Projects/node-custom-error/test.js:18:24)\n    at callFn (/Projects/node-custom-error/node_modules/mocha/lib/runnable.js:223:21)\n    at Hook.Runnable.run (/Projects/node-custom-error/node_modules/mocha/lib/runnable.js:216:7)\n    at next (/Projects/node-custom-error/node_modules/mocha/lib/runner.js:259:10)\n    at Object._onImmediate (/Projects/node-custom-error/node_modules/mocha/lib/runner.js:276:5)\n    at processImmediate [as _immediateCallback] (timers.js:330:15)\n```\nMultiple error objects are allowed to be passed, and are processed in order.\n\n## JSON support\nErrors can also be serialized into JSON format by using `error#toJSON();`. This will enumerate all of the hidden and custom properties, and also format the stack trace into an array of individual lines:\n\n```javascript\nconsole.log(error.toJSON()); // or console.log(JSON.stringify(error));\n```\noutputs\n```bash\n{ stack:\n   [ 'ValidationError: Missing field',\n     '    at Context.<anonymous> (/Projects/node-custom-error/test.js:17:24)',\n     '    at callFn (/Projects/node-custom-error/node_modules/mocha/lib/runnable.js:223:21)',\n     '    at Hook.Runnable.run (/Projects/node-custom-error/node_modules/mocha/lib/runnable.js:216:7)',\n     '    at next (/Projects/node-custom-error/node_modules/mocha/lib/runner.js:259:10)',\n     '    at Object._onImmediate (/Projects/node-custom-error/node_modules/mocha/lib/runner.js:276:5)',\n     '    at processImmediate [as _immediateCallback] (timers.js:330:15)' ],\n  arguments: undefined,\n  type: undefined,\n  required: 'Missing parameter x',\n  message: 'Missing Field' }\n```\n\n## Custom Constructor\nFinally, a custom function can be passed in as a 3rd argument. This will allow you to modify the custom error prototype without having to modify the original native Error prototype:\n\n```javascript\nvar HTTPError = createCustomError('HTTPError', null, function (message, code) {\n    var http = require('http');\n    // Set custom properties when thrown based on additional arguments\n    this.code = code;\n    this.status = http.STATUS_CODES[code];\n    // We can override the default message logic if desired:\n    this.message = message;\n});\nvar error = new HTTPError('You do not have permission', 403);\nconsole.log(error, [error.code, error.status]);\n// result: HTTPError: You do not have permission [ 403, \"Forbidden\" ]\n```\n\n## Notes\nCare is taken to preserve the built-in error handling behavior as much as possible, supporting:\n\n* `custom instanceOf Error`\n\n* `Error.prototype.isPrototypeOf(custom)`\n\n* `util.isError(custom)`\n\n* `custom = generator('message')`\n\n* `custom = new generator('message');`\n\nIn other words, you shouldn't have to worry about these errors affecting your syntax or existing code. Simply drop in place for any existing errors you're throwing and it should work just the same.\n","maintainers":[{"name":"jproulx","email":"github@jproulx.net"}],"time":{"modified":"2022-06-14T06:12:22.821Z","created":"2014-05-07T23:25:36.130Z","2.0.0":"2014-05-07T23:25:36.130Z","3.0.0":"2014-05-08T00:02:49.008Z","5.0.0":"2014-05-08T19:33:44.230Z","6.0.0":"2014-05-09T22:12:53.985Z","6.1.0":"2014-05-09T23:00:08.404Z","7.0.0":"2014-05-11T23:30:01.654Z"},"homepage":"https://github.com/jproulx/node-custom-error","keywords":["error","errors","error factory","custom error"],"repository":{"type":"git","url":"https://github.com/jproulx/node-custom-error.git"},"author":{"name":"Jesse Proulx","email":"github@jproulx.net"},"bugs":{"url":"https://github.com/jproulx/node-custom-error/issues"},"license":"ISC","readmeFilename":"README.md","users":{"jproulx":true,"twisterghost":true,"aaronmoodie":true,"jlagunas":true,"estliberitas":true}}