koa-any-error
install
$ npm install koa-any-error --save
errorFormats
{
json(error,ctx,options){return {}},
html(error,ctx,options){return ''},
text(error,ctx,options){return ''}
}
options
{
accepts:['json', 'html', 'text'],
isDev:true,
method:(error,ctx,options)=>{
}
}
// dependenciesconst Koa = ;const error = ;const app = ; const errorFormats = { logger; const status = errstatus || errstatusCode || 500; const result = code: errcode || status message: status message: errmessage success: false reason: "Unexpected" ; if env === "dev" result"stack" = errstack; return result; }; // middlewareapp;
notes
请务必在初始化在 koa 中间件的第一顺位 , 避免不必要问题