{"_id":"failure","_rev":"269117","name":"failure","description":"Easily generate \"custom\" error objects with addition properties which can be stringfied with JSON.stringify","dist-tags":{"latest":"1.1.1"},"maintainers":[{"name":"3rdeden","email":""}],"time":{"modified":"2023-06-28T12:14:12.000Z","created":"2015-04-10T12:10:37.626Z","1.1.1":"2015-07-22T17:56:47.493Z","1.1.0":"2015-07-22T13:04:11.643Z","1.0.0":"2015-04-10T12:10:37.626Z"},"users":{},"author":{"name":"Arnout Kazemier"},"repository":{"type":"git","url":"git+https://github.com/unshiftio/failure.git"},"versions":{"1.1.1":{"name":"failure","version":"1.1.1","description":"Easily generate \"custom\" error objects with addition properties which can be stringfied with JSON.stringify","main":"index.js","scripts":{"100%":"istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100","test":"mocha test.js","watch":"mocha --watch test.js","coverage":"istanbul cover ./node_modules/.bin/_mocha -- test.js","test-travis":"istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js"},"repository":{"type":"git","url":"git+https://github.com/unshiftio/failure.git"},"keywords":["failure","error","errs","err","errors","fail","throw","custom"],"author":{"name":"Arnout Kazemier"},"license":"MIT","bugs":{"url":"https://github.com/unshiftio/failure/issues"},"homepage":"https://github.com/unshiftio/failure","devDependencies":{"assume":"1.2.x","istanbul":"0.3.x","mocha":"2.2.x","pre-commit":"1.0.x"},"gitHead":"43d48c1a60528ad8ca2fe9e0f6364195fef8dd68","_id":"failure@1.1.1","_shasum":"a8e83d3b1602d2468bff6ad4d9071e0103b81a87","_from":".","_npmVersion":"2.9.1","_nodeVersion":"0.12.3","_npmUser":{"name":"3rdeden","email":"npm@3rd-Eden.com"},"maintainers":[{"name":"3rdeden","email":""}],"dist":{"shasum":"a8e83d3b1602d2468bff6ad4d9071e0103b81a87","size":4123,"noattachment":false,"key":"/failure/-/failure-1.1.1.tgz","tarball":"http://name.csiicloud.com:7001/failure/download/failure-1.1.1.tgz"},"directories":{},"publish_time":1437587807493,"_hasShrinkwrap":false,"_cnpm_publish_time":1437587807493,"_cnpmcore_publish_time":"2021-12-16T19:48:46.605Z"},"1.1.0":{"name":"failure","version":"1.1.0","description":"Easily generate \"custom\" error objects with addition properties which can be stringfied with JSON.stringify","main":"index.js","scripts":{"100%":"istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100","test":"mocha test.js","watch":"mocha --watch test.js","coverage":"istanbul cover ./node_modules/.bin/_mocha -- test.js","test-travis":"istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js"},"repository":{"type":"git","url":"git+https://github.com/unshiftio/failure.git"},"keywords":["failure","error","errs","err","errors","fail","throw","custom"],"author":{"name":"Arnout Kazemier"},"license":"MIT","bugs":{"url":"https://github.com/unshiftio/failure/issues"},"homepage":"https://github.com/unshiftio/failure","devDependencies":{"assume":"1.2.x","istanbul":"0.3.x","mocha":"2.2.x","pre-commit":"1.0.x"},"gitHead":"429d70fe863df7b20696aa9f48de2acb4771fe7e","_id":"failure@1.1.0","_shasum":"024a290c7b34d2c4a0b14e80a813dd5fa129b282","_from":".","_npmVersion":"2.9.1","_nodeVersion":"0.12.3","_npmUser":{"name":"3rdeden","email":"npm@3rd-Eden.com"},"maintainers":[{"name":"3rdeden","email":""}],"dist":{"shasum":"024a290c7b34d2c4a0b14e80a813dd5fa129b282","size":4069,"noattachment":false,"key":"/failure/-/failure-1.1.0.tgz","tarball":"http://name.csiicloud.com:7001/failure/download/failure-1.1.0.tgz"},"directories":{},"publish_time":1437570251643,"_hasShrinkwrap":false,"_cnpm_publish_time":1437570251643,"_cnpmcore_publish_time":"2021-12-16T19:48:46.868Z"},"1.0.0":{"name":"failure","version":"1.0.0","description":"Easily generate \"custom\" error objects with addition properties which can be stringfied with JSON.stringify","main":"index.js","scripts":{"100%":"istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100","test":"mocha test.js","watch":"mocha --watch test.js","coverage":"istanbul cover ./node_modules/.bin/_mocha -- test.js","test-travis":"istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js"},"repository":{"type":"git","url":"https://github.com/unshiftio/failure"},"keywords":["failure","error","errs","err","errors","fail","throw","custom"],"author":{"name":"Arnout Kazemier"},"license":"MIT","bugs":{"url":"https://github.com/unshiftio/failure/issues"},"homepage":"https://github.com/unshiftio/failure","devDependencies":{"assume":"1.2.x","istanbul":"0.3.x","mocha":"2.2.x","pre-commit":"1.0.x"},"gitHead":"c93244701b712af6fbc54bd3f9e60da20d9293f9","_id":"failure@1.0.0","_shasum":"55192e507b618e74825075143435c5741c69bb04","_from":".","_npmVersion":"2.7.5","_nodeVersion":"0.10.35","_npmUser":{"name":"3rdeden","email":"npm@3rd-Eden.com"},"maintainers":[{"name":"3rdeden","email":""}],"dist":{"shasum":"55192e507b618e74825075143435c5741c69bb04","size":3933,"noattachment":false,"key":"/failure/-/failure-1.0.0.tgz","tarball":"http://name.csiicloud.com:7001/failure/download/failure-1.0.0.tgz"},"directories":{},"publish_time":1428667837626,"_hasShrinkwrap":false,"_cnpm_publish_time":1428667837626,"_cnpmcore_publish_time":"2021-12-16T19:48:47.123Z"}},"readme":"# failure\n\n[![Made by unshift][made-by]](http://unshift.io)[![Version npm][version]](http://browsenpm.org/package/failure)[![Build Status][build]](https://travis-ci.org/unshiftio/failure)[![Dependencies][david]](https://david-dm.org/unshiftio/failure)[![Coverage Status][cover]](https://coveralls.io/r/unshiftio/failure?branch=master)[![IRC channel][irc]](http://webchat.freenode.net/?channels=unshift)\n\n[made-by]: https://img.shields.io/badge/made%20by-unshift-00ffcc.svg?style=flat-square\n[version]: https://img.shields.io/npm/v/failure.svg?style=flat-square\n[build]: https://img.shields.io/travis/unshiftio/failure/master.svg?style=flat-square\n[david]: https://img.shields.io/david/unshiftio/failure.svg?style=flat-square\n[cover]: https://img.shields.io/coveralls/unshiftio/failure/master.svg?style=flat-square\n[irc]: https://img.shields.io/badge/IRC-irc.freenode.net%23unshift-00a8ff.svg?style=flat-square\n\nFailure is a small helper library which allows you to easily generate custom\nerror objects which can hold addition properties which could be helpful for\ndebugging your application. In addition to that, it automatically adds a missing\n`toJSON` function to the Error object so you can actually get the message and\nstack trace once you `JSON.stringify` the error instance.\n\n## Installation\n\nThe module is written with browsers and servers in mind and should run in any\nenvironment that runs ES3. The module it self is released in the public npm\nregistry and can be installed using:\n\n```\nnpm install --save failure\n```\n\nThe `--save` flag tells npm to automatically add the installed version to your\n`package.json` file as new dependency.\n\n## Usage\n\nFirst of all, start with including this module in your code:\n\n```js\n'use strict';\n\nvar failure = require('failure');\n```\n\nNow every time you want to pass or create a `new Error` instance, you can use\nthe `failure` function to generate the error for you. The failure method accepts\n2 arguments:\n\n1. An `Error` instance that just needs extra props, or a `string` that should be\n   transformed to an `Error`. Please do note that when using a string you will\n   have an extra trace in your stack trace as the stack trace will be made inside\n   the `failure` function instead of where you called the `failure` function.\n2. An object with extra properties that should be introduced on the supplied or\n   generated `Error` instance. These properties will not override existing\n   properties on the `Error` instance.\n\nBefore the function returns the generated `Error` instance it checks if it also\nneeds to add the missing `.toJSON` method.\n\nBelow is a small usage example on how you could use this to provide extra\ninformation when things start failing when you make an HTTP request somewhere.\nIf request something with an incorrect status code, you might want to know what\nstatusCode was received, so we can easily add that to the Error object. Same as\nparse errors for JSON, you probably want to know what you received and failed.\n\n```js\nrequest('https://googlllll.com', function (err, res, body) {\n  if (err) return next(err);\n  if (res.statusCode !== 200) return next(failure('Invalid statusCode'), {\n    statusCode: res.statusCode\n  });\n\n  try { body = JSON.parse(body); }\n  catch (e) {\n    return next(failure(e, { \n      body: body \n    }));\n  }\n\n  next(undefined, body);\n})\n```\n\n## License\n\nMIT\n","_attachments":{},"homepage":"https://github.com/unshiftio/failure","bugs":{"url":"https://github.com/unshiftio/failure/issues"},"license":"MIT"}