{"_id":"bounce","_rev":"59258","name":"bounce","description":"Selective error catching and rewrite rules","dist-tags":{"latest":"1.2.3"},"maintainers":[{"name":"hueniverse","email":"eran@hammer.io"}],"time":{"modified":"2021-06-03T10:19:18.000Z","created":"2017-11-01T20:44:36.465Z","1.2.3":"2018-11-11T02:09:15.474Z","1.2.2":"2018-11-03T00:17:48.404Z","1.2.1":"2018-11-01T07:32:47.231Z","1.2.0":"2017-11-06T09:36:41.625Z","1.1.0":"2017-11-06T07:23:03.309Z","1.0.3":"2017-11-03T09:40:28.581Z","1.0.2":"2017-11-03T09:11:39.782Z","1.0.1":"2017-11-02T17:54:58.863Z","0.0.0":"2017-11-01T20:44:36.465Z","1.0.0":"2017-11-02T05:48:38.227Z"},"users":{},"repository":{"type":"git","url":"git://github.com/hapijs/bounce.git"},"versions":{"1.2.3":{"name":"bounce","description":"Selective error catching and rewrite rules","version":"1.2.3","repository":{"type":"git","url":"git://github.com/hapijs/bounce.git"},"main":"lib/index.js","keywords":["error","catch"],"dependencies":{"boom":"7.x.x","hoek":"6.x.x"},"devDependencies":{"code":"5.x.x","lab":"17.x.x"},"scripts":{"test":"lab -a code -t 100 -L","test-cov-html":"lab -a code -r html -o coverage.html -L"},"license":"BSD-3-Clause","gitHead":"9259cfafac7c9258c096ac02388812f15fda6478","bugs":{"url":"https://github.com/hapijs/bounce/issues"},"homepage":"https://github.com/hapijs/bounce#readme","_id":"bounce@1.2.3","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"hueniverse","email":"eran@hammer.io"},"dist":{"shasum":"2b286d36eb21d5f08fe672dd8cd37a109baad121","size":4965,"noattachment":false,"key":"/bounce/-/bounce-1.2.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/bounce/download/bounce-1.2.3.tgz"},"maintainers":[{"name":"hueniverse","email":"eran@hammer.io"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bounce_1.2.3_1541902155332_0.9663525213754494"},"_hasShrinkwrap":false,"publish_time":1541902155474,"_cnpm_publish_time":1541902155474,"deprecated":"This module has moved and is now available at @hapi/bounce. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues."},"1.2.2":{"name":"bounce","description":"Selective error catching and rewrite rules","version":"1.2.2","repository":{"type":"git","url":"git://github.com/hapijs/bounce.git"},"main":"lib/index.js","keywords":["error","catch"],"dependencies":{"boom":"7.x.x","hoek":"6.x.x"},"devDependencies":{"code":"5.x.x","lab":"17.x.x"},"scripts":{"test":"lab -a code -t 100 -L","test-cov-html":"lab -a code -r html -o coverage.html -L"},"license":"BSD-3-Clause","gitHead":"b7d8b2e9cd4263677370d8e470b12fa5fde09817","bugs":{"url":"https://github.com/hapijs/bounce/issues"},"homepage":"https://github.com/hapijs/bounce#readme","_id":"bounce@1.2.2","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"hueniverse","email":"eran@hammer.io"},"dist":{"shasum":"b73fabe05675c5190003978a54a577aa8a3b8ea3","size":4932,"noattachment":false,"key":"/bounce/-/bounce-1.2.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/bounce/download/bounce-1.2.2.tgz"},"maintainers":[{"name":"hueniverse","email":"eran@hammer.io"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bounce_1.2.2_1541204268273_0.6396666719911757"},"_hasShrinkwrap":false,"publish_time":1541204268404,"_cnpm_publish_time":1541204268404,"deprecated":"This module has moved and is now available at @hapi/bounce. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues."},"1.2.1":{"name":"bounce","description":"Selective error catching and rewrite rules","version":"1.2.1","repository":{"type":"git","url":"git://github.com/hapijs/bounce.git"},"main":"lib/index.js","keywords":["error","catch"],"engines":{"node":">=8.12.0"},"dependencies":{"boom":"7.x.x","hoek":"6.x.x"},"devDependencies":{"code":"5.x.x","lab":"17.x.x"},"scripts":{"test":"lab -a code -t 100 -L","test-cov-html":"lab -a code -r html -o coverage.html -L"},"license":"BSD-3-Clause","gitHead":"9e5e0e7423fa54bd2a962c36cc9623c45822ada5","bugs":{"url":"https://github.com/hapijs/bounce/issues"},"homepage":"https://github.com/hapijs/bounce#readme","_id":"bounce@1.2.1","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"hueniverse","email":"eran@hammer.io"},"dist":{"shasum":"0dfae78dffb68e36c89f8ebddc6a9c355daca306","size":4947,"noattachment":false,"key":"/bounce/-/bounce-1.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/bounce/download/bounce-1.2.1.tgz"},"maintainers":[{"name":"hueniverse","email":"eran@hammer.io"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bounce_1.2.1_1541057567084_0.3135724004368685"},"_hasShrinkwrap":false,"publish_time":1541057567231,"_cnpm_publish_time":1541057567231,"deprecated":"This module has moved and is now available at @hapi/bounce. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues."},"1.2.0":{"name":"bounce","description":"Selective error catching and rewrite rules","version":"1.2.0","repository":{"type":"git","url":"git://github.com/hapijs/bounce.git"},"main":"lib/index.js","keywords":["error","catch"],"engines":{"node":">=8.9.0"},"dependencies":{"boom":"7.x.x","hoek":"5.x.x"},"devDependencies":{"code":"5.x.x","lab":"15.x.x"},"scripts":{"test":"lab -a code -t 100 -L","test-cov-html":"lab -a code -r html -o coverage.html -L"},"license":"BSD-3-Clause","gitHead":"dce0a1bba1400d8d4397bb1887d567106da699d7","bugs":{"url":"https://github.com/hapijs/bounce/issues"},"homepage":"https://github.com/hapijs/bounce#readme","_id":"bounce@1.2.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.0","_npmUser":{"name":"hueniverse","email":"eran@hammer.io"},"dist":{"shasum":"e3bac68c73fd256e38096551efc09f504873c8c8","size":4989,"noattachment":false,"key":"/bounce/-/bounce-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/bounce/download/bounce-1.2.0.tgz"},"maintainers":[{"name":"hueniverse","email":"eran@hammer.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bounce-1.2.0.tgz_1509961001524_0.1863099925685674"},"directories":{},"publish_time":1509961001625,"_hasShrinkwrap":false,"_cnpm_publish_time":1509961001625,"deprecated":"This module has moved and is now available at @hapi/bounce. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues."},"1.1.0":{"name":"bounce","description":"Selective error catching and rewrite rules","version":"1.1.0","repository":{"type":"git","url":"git://github.com/hapijs/bounce.git"},"main":"lib/index.js","keywords":["error","catch"],"engines":{"node":">=8.9.0"},"dependencies":{"boom":"7.x.x","hoek":"5.x.x"},"devDependencies":{"code":"5.x.x","lab":"15.x.x"},"scripts":{"test":"lab -a code -t 100 -L","test-cov-html":"lab -a code -r html -o coverage.html -L"},"license":"BSD-3-Clause","gitHead":"19e2d10c58570270bed59cd5c89283832a7fadc3","bugs":{"url":"https://github.com/hapijs/bounce/issues"},"homepage":"https://github.com/hapijs/bounce#readme","_id":"bounce@1.1.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.0","_npmUser":{"name":"hueniverse","email":"eran@hammer.io"},"dist":{"shasum":"0538d1821101107818646fd10c4f9ad0af2a1023","size":4627,"noattachment":false,"key":"/bounce/-/bounce-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/bounce/download/bounce-1.1.0.tgz"},"maintainers":[{"name":"hueniverse","email":"eran@hammer.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bounce-1.1.0.tgz_1509952983240_0.17449252889491618"},"directories":{},"publish_time":1509952983309,"_hasShrinkwrap":false,"_cnpm_publish_time":1509952983309,"deprecated":"This module has moved and is now available at @hapi/bounce. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues."},"1.0.3":{"name":"bounce","description":"Selective error catching and rewrite rules","version":"1.0.3","repository":{"type":"git","url":"git://github.com/hapijs/bounce.git"},"main":"lib/index.js","keywords":["error","catch"],"engines":{"node":">=8.9.0"},"dependencies":{"boom":"7.x.x","hoek":"5.x.x"},"devDependencies":{"code":"5.x.x","lab":"15.x.x"},"scripts":{"test":"lab -a code -t 100 -L","test-cov-html":"lab -a code -r html -o coverage.html -L"},"license":"BSD-3-Clause","gitHead":"75976dde02035c3051bb227c67b2594df1980814","bugs":{"url":"https://github.com/hapijs/bounce/issues"},"homepage":"https://github.com/hapijs/bounce#readme","_id":"bounce@1.0.3","_npmVersion":"5.5.1","_nodeVersion":"8.9.0","_npmUser":{"name":"hueniverse","email":"eran@hammer.io"},"dist":{"shasum":"21f1b7d529419d821904461325a27744d95a5611","size":4484,"noattachment":false,"key":"/bounce/-/bounce-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/bounce/download/bounce-1.0.3.tgz"},"maintainers":[{"name":"hueniverse","email":"eran@hammer.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bounce-1.0.3.tgz_1509702028499_0.25577562511898577"},"directories":{},"publish_time":1509702028581,"_hasShrinkwrap":false,"_cnpm_publish_time":1509702028581,"deprecated":"This module has moved and is now available at @hapi/bounce. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues."},"1.0.2":{"name":"bounce","description":"Selective error catching and rewrite rules","version":"1.0.2","repository":{"type":"git","url":"git://github.com/hapijs/bounce.git"},"main":"lib/index.js","keywords":["error","catch"],"engines":{"node":">=8.9.0"},"dependencies":{"boom":"7.x.x","hoek":"5.x.x"},"devDependencies":{"code":"5.x.x","lab":"15.x.x"},"scripts":{"test":"lab -a code -t 100 -L","test-cov-html":"lab -a code -r html -o coverage.html -L"},"license":"BSD-3-Clause","gitHead":"28d732e1305decafb4c85e160f62b30b0f4b935c","bugs":{"url":"https://github.com/hapijs/bounce/issues"},"homepage":"https://github.com/hapijs/bounce#readme","_id":"bounce@1.0.2","_npmVersion":"5.5.1","_nodeVersion":"8.9.0","_npmUser":{"name":"hueniverse","email":"eran@hammer.io"},"dist":{"shasum":"ad138764beabb44f1ed8e7b71008331bf49a1622","size":4436,"noattachment":false,"key":"/bounce/-/bounce-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/bounce/download/bounce-1.0.2.tgz"},"maintainers":[{"name":"hueniverse","email":"eran@hammer.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bounce-1.0.2.tgz_1509700299724_0.34092277591116726"},"directories":{},"publish_time":1509700299782,"_hasShrinkwrap":false,"_cnpm_publish_time":1509700299782,"deprecated":"This module has moved and is now available at @hapi/bounce. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues."},"1.0.1":{"name":"bounce","description":"Selective error catching and rewrite rules","version":"1.0.1","repository":{"type":"git","url":"git://github.com/hapijs/bounce.git"},"main":"lib/index.js","keywords":["error","catch"],"engines":{"node":">=8.9.0"},"dependencies":{"hoek":"5.x.x"},"devDependencies":{"boom":"6.x.x","code":"5.x.x","lab":"15.x.x"},"scripts":{"test":"lab -a code -t 100 -L","test-cov-html":"lab -a code -r html -o coverage.html -L"},"license":"BSD-3-Clause","gitHead":"b35298c1ad2f5cf32004b74cfe508b76ed435ab1","bugs":{"url":"https://github.com/hapijs/bounce/issues"},"homepage":"https://github.com/hapijs/bounce#readme","_id":"bounce@1.0.1","_npmVersion":"5.5.1","_nodeVersion":"8.9.0","_npmUser":{"name":"hueniverse","email":"eran@hammer.io"},"dist":{"shasum":"fafe7ed0ea6965226de6046c9821ba5c77440826","size":4461,"noattachment":false,"key":"/bounce/-/bounce-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/bounce/download/bounce-1.0.1.tgz"},"maintainers":[{"name":"hueniverse","email":"eran@hammer.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bounce-1.0.1.tgz_1509645298778_0.6659522447735071"},"directories":{},"publish_time":1509645298863,"_hasShrinkwrap":false,"_cnpm_publish_time":1509645298863,"deprecated":"This module has moved and is now available at @hapi/bounce. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues."},"0.0.0":{"name":"bounce","description":"Selective error catching and rewrite rules","version":"0.0.0","repository":{"type":"git","url":"git://github.com/hapijs/bounce.git"},"main":"lib/index.js","keywords":["error","catch"],"engines":{"node":">=8.9.0"},"dependencies":{"boom":"6.x.x"},"devDependencies":{"code":"5.x.x","lab":"15.x.x"},"scripts":{"test":"lab -a code -t 100 -L -v","test-cov-html":"lab -a code -r html -o coverage.html -L","toc":"node generate-toc.js","version":"npm run toc && git add README.md"},"license":"BSD-3-Clause","gitHead":"72c276c8e3bb84efc2368bef90aea3927bb13c35","bugs":{"url":"https://github.com/hapijs/bounce/issues"},"homepage":"https://github.com/hapijs/bounce#readme","_id":"bounce@0.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.0","_npmUser":{"name":"hueniverse","email":"eran@hammer.io"},"dist":{"shasum":"2050992a1584a6a11454b948d99b6d2700413b29","size":1650,"noattachment":false,"key":"/bounce/-/bounce-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/bounce/download/bounce-0.0.0.tgz"},"maintainers":[{"name":"hueniverse","email":"eran@hammer.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bounce-0.0.0.tgz_1509569076339_0.409978193230927"},"directories":{},"publish_time":1509569076465,"_hasShrinkwrap":false,"_cnpm_publish_time":1509569076465,"deprecated":"This module has moved and is now available at @hapi/bounce. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues."},"1.0.0":{"name":"bounce","description":"Selective error catching and rewrite rules","version":"1.0.0","repository":{"type":"git","url":"git://github.com/hapijs/bounce.git"},"main":"lib/index.js","keywords":["error","catch"],"engines":{"node":">=8.9.0"},"dependencies":{},"devDependencies":{"boom":"6.x.x","code":"5.x.x","lab":"15.x.x"},"scripts":{"test":"lab -a code -t 100 -L","test-cov-html":"lab -a code -r html -o coverage.html -L"},"license":"BSD-3-Clause","gitHead":"982f33b9d7c365daba5b6689572912d6b51c2879","bugs":{"url":"https://github.com/hapijs/bounce/issues"},"homepage":"https://github.com/hapijs/bounce#readme","_id":"bounce@1.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.0","_npmUser":{"name":"hueniverse","email":"eran@hammer.io"},"dist":{"shasum":"040280dd38adbb25549013544fe9faca55f9e7c6","size":4483,"noattachment":false,"key":"/bounce/-/bounce-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/bounce/download/bounce-1.0.0.tgz"},"maintainers":[{"name":"hueniverse","email":"eran@hammer.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bounce-1.0.0.tgz_1509601718140_0.6831676005385816"},"directories":{},"publish_time":1509601718227,"_hasShrinkwrap":false,"_cnpm_publish_time":1509601718227,"deprecated":"This module has moved and is now available at @hapi/bounce. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues."}},"readme":"# bounce\r\n\r\nSelective error catching and rewrite rules\r\n\r\n[![Build Status](https://secure.travis-ci.org/hapijs/bounce.svg)](http://travis-ci.org/hapijs/bounce)\r\n\r\nLead Maintainer - [Eran Hammer](https://github.com/hueniverse)\r\n\r\n## Introduction\r\n\r\nWorking with `async`/`await` introduces a new challange in handling errors. Unlike callbacks, which\r\nprovide a dual mechanism for passing application errors via the callback `err` argument and\r\ndeveloper errors via exceptions, `await` combines these two channels into one.\r\n\r\nIt is common practice to ignore application errors in background processing or when there is no\r\nuseful fallback. In those cases, it is still imperative to allow developer errors to surface and\r\nnot get swallowed.\r\n\r\nFor more information read:\r\n- [Learning to Throw Again](https://medium.com/@eranhammer/learning-to-throw-again-79b498504d28)\r\n- [Catching without Awaiting](https://medium.com/@eranhammer/catching-without-awaiting-b2cb7df45790)\r\n\r\nFor example:\r\n\r\n```js\r\nasync function email(user) {\r\n\r\n    if (!user.address) {\r\n        throw new Error('User has no email address');\r\n    }\r\n\r\n    const message = 'Welcome!';\r\n    if (user.name) {\r\n        message = `Welcome ${user.name}!`;\r\n    }\r\n\r\n    await mailer.send(user.address, message);\r\n}\r\n\r\nasync function register(address, name) {\r\n\r\n    const user = { address, name };\r\n    const id = await db.user.insert(user);\r\n    user.id = id;\r\n\r\n    try {\r\n        await email(user);\r\n    }\r\n    catch (err) { }             // Ignore errors\r\n\r\n    return user;\r\n}\r\n```\r\n\r\nThis will fail silently every time the user has a `name` because it is reassigning a value to a\r\n`const` variable. However, because `email()` errors are ignored, system errors are ignored as well.\r\nThe idea is that `email()` can be used in both critical and non-critical paths. In the critical\r\npaths, errors are checked and addressed, but in the non-critical paths, errors are simply ignored.\r\n\r\nThis can be solved by adding a `rethrow()` statement:\r\n\r\n```js\r\nconst Bounce = require('bounce');\r\n\r\nasync function register(address, name) {\r\n\r\n    const user = { address, name };\r\n    const id = await db.user.insert(user);\r\n    user.id = id;\r\n\r\n    try {\r\n        await email(user);\r\n    }\r\n    catch (err) {\r\n        Bounce.rethrow(err, 'system');  // Rethrows system errors and ignores application errors\r\n    }\r\n\r\n    return user;\r\n}\r\n```\r\n\r\n## Usage\r\n\r\n### `rethrow(err, types, [options])`\r\n\r\nThrows the error passed if it matches any of the specified rules where:\r\n- `err` - the error.\r\n- `type` - a single item or an array of items of:\r\n    - An error constructor (e.g. `SyntaxError`).\r\n    - `'system'` - matches any languange native error or node assertions.\r\n    - `'boom'` - matches [**boom**](https://github.com/hapijs/boom) errors.\r\n    - an object where each property is compared with the error and must match the error property\r\n      value. All the properties in the object must match the error but do not need to include all\r\n      the error properties.\r\n- `options` - optional object where:\r\n    - `decorate` - an object which is assigned to the `err`, copying the properties onto the error.\r\n    - `override` - an error used to override `err` when `err` matches. If used with `decorate`,\r\n      the `override` object is modified.\r\n    - `return` - if `true`, the error is returned instead of thrown. Defaults to `false`.\r\n\r\n### `ignore(err, types, [options])`\r\n\r\nThe opposite action of `rethrow()`. Ignores any errors matching the specified `types`. Any error\r\nnot matching is thrown after applying the `options`.\r\n\r\n### `background(operation, [action], [types], [options])`\r\n\r\nAwaits for the value to resolve in the background and then apply either the `rethrow()` or `ignore()`\r\nactions where:\r\n- `operation` - a function, promise, or value that is `await`ed on inside a `try...catch` and any\r\n  error thrown processed by the `action` rule.\r\n- `action` - one of `'rethrow'` or `'ignore'`. Defaults to `'rethrow'`.\r\n- `types` - same as the `types` argument passed to `rethrow()` or `ignore()`. Defaults to `'system'`.\r\n- `options` - same as the `options` argument passed to `rethrow()` or `ignore()`.\r\n\r\n### `isBoom(err)`\r\n\r\nReturns `true` when `err` is a [**boom**](https://github.com/hapijs/boom) error.\r\n\r\n### `isError(err)`\r\n\r\nReturns `true` when `err` is an error.\r\n\r\n### `isSystem(err)`\r\n\r\nReturn `true` when `err` is one of:\r\n- `EvalError`\r\n- `RangeError`\r\n- `ReferenceError`\r\n- `SyntaxError`\r\n- `TypeError`\r\n- `URIError`\r\n- Node's `AssertionError`\r\n","_attachments":{},"homepage":"https://github.com/hapijs/bounce#readme","bugs":{"url":"https://github.com/hapijs/bounce/issues"},"license":"BSD-3-Clause"}