{"name":"koa-onerror","version":"5.0.1","description":"koa error handler, hack ctx.onerror","repository":{"type":"git","url":"git://github.com/koajs/onerror.git"},"keywords":["koa","middleware","error"],"author":{"name":"dead_horse","email":"dead_horse@qq.com"},"license":"MIT","bugs":{"url":"https://github.com/koajs/onerror/issues"},"homepage":"https://github.com/koajs/onerror","engines":{"node":">= 18.19.0"},"dependencies":{"escape-html":"^1.0.3","stream-wormhole":"^2.0.1"},"devDependencies":{"@arethetypeswrong/cli":"^0.17.3","@eggjs/bin":"7","@eggjs/supertest":"^8.2.0","@eggjs/tsconfig":"1","@types/escape-html":"^1.0.4","@types/koa":"^2.15.0","@types/mocha":"10","@types/node":"22","co-busboy":"^1.4.0","eslint":"8","eslint-config-egg":"14","formstream":"^1.5.1","koa":"2","mm":"^4.0.2","rimraf":"6","snap-shot-it":"^7.9.10","tshy":"3","tshy-after":"1","typescript":"5","urllib":"^4.6.11"},"scripts":{"lint":"eslint --cache src test --ext .ts","pretest":"npm run clean && npm run lint -- --fix","test":"egg-bin test","test:snapshot:update":"SNAPSHOT_UPDATE=1 egg-bin test","preci":"npm run clean &&  npm run lint","ci":"egg-bin cov","postci":"npm run prepublishOnly && npm run clean","clean":"rimraf dist","prepublishOnly":"tshy && tshy-after && attw --pack"},"type":"module","tshy":{"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./package.json":"./package.json"},"types":"./dist/commonjs/index.d.ts","main":"./dist/commonjs/index.js","module":"./dist/esm/index.js","_id":"koa-onerror@5.0.1","gitHead":"d8503390716281ba590f5b2c98b425ae1301c43c","_nodeVersion":"20.18.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-mSdakWWkZASupPZe661zhSwa/szIvskdmNpLn9gRmrcI2iktDDLi+u0c6KuG6mI6E6Fh8btVMdx0u40/2IvxQw==","shasum":"b2d2c3674e1338ca8c0061bed819b44a94e186e3","tarball":"http://registry-npm.ywwl.com/koa-onerror/download/koa-onerror-5.0.1.tgz","fileCount":17,"unpackedSize":39398,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/koa-onerror@5.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDAZ0rK/HvM4WbJYjkDSOMC86elgHbu0JdBcYZ9KqXZKgIgH5ynmPm+Zpeb3P8ZAW8c/4fNgVDxYg5Qoy02puaKXko="}],"size":8653,"noattachment":false,"key":"/koa-onerror/-/koa-onerror-5.0.1.tgz"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"directories":{},"maintainers":[{"name":"dead_horse","email":"dead_horse@qq.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/koa-onerror_5.0.1_1738499170130_0.6352534564429653"},"_hasShrinkwrap":false,"readme":"# koa-onerror\n\n[![NPM version][npm-image]][npm-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n[![Node.js Version](https://img.shields.io/node/v/koa-onerror.svg?style=flat)](https://nodejs.org/en/download/)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)\n\n[npm-image]: https://img.shields.io/npm/v/koa-onerror.svg?style=flat\n[npm-url]: https://npmjs.org/package/koa-onerror\n[codecov-image]: https://codecov.io/gh/koajs/onerror/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/koajs/onerror\n[snyk-image]: https://snyk.io/test/npm/koa-onerror/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/koa-onerror\n[download-image]: https://img.shields.io/npm/dm/koa-onerror.svg?style=flat-square\n[download-url]: https://npmjs.org/package/koa-onerror\n\nan error handler for koa, hack ctx.onerror.\n\ndifferent with [koa-error](https://github.com/koajs/error):\n\n- we can not just use try catch to handle all errors, steams' and events'\nerrors are directly handle by `ctx.onerror`, so if we want to handle all\nerrors in one place, the only way i can see is to hack `ctx.onerror`.\n- it is more customizable.\n\n## install\n\n```bash\nnpm install koa-onerror\n```\n\n## Usage\n\n```js\nconst fs = require('fs');\nconst Koa = require('koa');\nconst { onerror } = require('koa-onerror');\n\nconst app = new Koa();\n\nonerror(app);\n\napp.use(ctx => {\n  // foo();\n  ctx.body = fs.createReadStream('not exist');\n});\n```\n\n## Options\n\n```js\nonerror(app, options);\n```\n\n- **all**: if `options.all` exist, ignore negotiation\n- **text**: text error handler\n- **json**: json error handler\n- **html**: html error handler\n- **redirect**: if accept `html` or `text`, can redirect to another error page\n\ncheck out default handler to write your own handler.\n\n## Status and Headers\n\n`koa-onerror` will automatic set `err.status` as response status code, and `err.headers` as response headers.\n\n## License\n\n[MIT](LICENSE)\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=koajs/onerror)](https://github.com/koajs/onerror/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1738499170337,"_cnpm_publish_time":1738499170337,"dist-tags":{"latest":"5.0.1"}}