- Notifications
You must be signed in to change notification settings - Fork20
an error handler for koa, hack ctx.onerror
License
NotificationsYou must be signed in to change notification settings
koajs/onerror
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
an error handler for koa, hack ctx.onerror.
different withkoa-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 allerrors in one place, the only way i can see is to hackctx.onerror
. - it is more customizable.
npm install koa-onerror
constfs=require('fs');constKoa=require('koa');const{ onerror}=require('koa-onerror');constapp=newKoa();onerror(app);app.use(ctx=>{// foo();ctx.body=fs.createReadStream('not exist');});
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
ortext
, can redirect to another error page
check out default handler to write your own handler.
koa-onerror
will automatic seterr.status
as response status code, anderr.headers
as response headers.
Made withcontributors-img.
About
an error handler for koa, hack ctx.onerror
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.