New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

koa-onerror

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-onerror

koa error handler, hack ctx.onerror

  • 5.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28K
increased by5.25%
Maintainers
0
Weekly downloads
 
Created
Source

koa-onerror

NPM version Test coverage Known Vulnerabilities npm download Node.js Version PRs Welcome

an error handler for koa, hack ctx.onerror.

different with koa-error:

  • we can not just use try catch to handle all errors, steams' and events' errors are directly handle by ctx.onerror, so if we want to handle all errors in one place, the only way i can see is to hack ctx.onerror.
  • it is more customizable.

install

npm install koa-onerror

Usage

const fs = require('fs');
const Koa = require('koa');
const { onerror } = require('koa-onerror');

const app = new Koa();

onerror(app);

app.use(ctx => {
  // foo();
  ctx.body = fs.createReadStream('not exist');
});

Options

onerror(app, options);
  • all: if options.all exist, ignore negotiation
  • text: text error handler
  • json: json error handler
  • html: html error handler
  • redirect: if accept html or text, can redirect to another error page

check out default handler to write your own handler.

Status and Headers

koa-onerror will automatic set err.status as response status code, and err.headers as response headers.

License

MIT

Contributors

Contributors

Made with contributors-img.

Keywords

FAQs

Package last updated on 02 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc