Update to Koa 2
This commit is contained in:
parent
42b6cd5a32
commit
87459b2acc
15 changed files with 467 additions and 419 deletions
|
@ -3,16 +3,16 @@ import debuglog from 'debug';
|
|||
const debug = debuglog('combine.fm');
|
||||
|
||||
export default function (raven) {
|
||||
return function* error(next) {
|
||||
this.set('Server', 'Nintendo 64');
|
||||
return async function error(ctx, next) {
|
||||
ctx.set('Server', 'Nintendo 64');
|
||||
try {
|
||||
yield next;
|
||||
await next();
|
||||
} catch (err) {
|
||||
if (err.status === 404) {
|
||||
this.body = '404 Page Not Found';
|
||||
ctx.body = '404 Page Not Found';
|
||||
} else if (err.status >= 400 && err.status < 500) {
|
||||
this.status = err.status;
|
||||
this.body = err.error;
|
||||
ctx.status = err.status;
|
||||
ctx.body = err.error;
|
||||
} else {
|
||||
debug('Error: %o', err);
|
||||
raven.captureException(err);
|
||||
|
@ -20,21 +20,21 @@ export default function (raven) {
|
|||
}
|
||||
}
|
||||
|
||||
if (this.status !== 404) return;
|
||||
if (ctx.status !== 404) return;
|
||||
|
||||
switch (this.accepts('html', 'json')) {
|
||||
switch (ctx.accepts('html', 'json')) {
|
||||
case 'html':
|
||||
this.type = 'html';
|
||||
this.body = '404 Page Not Found';
|
||||
ctx.type = 'html';
|
||||
ctx.body = '404 Page Not Found';
|
||||
break;
|
||||
case 'json':
|
||||
this.body = {
|
||||
ctx.body = {
|
||||
message: 'Page Not Found',
|
||||
};
|
||||
break;
|
||||
default:
|
||||
this.type = 'text';
|
||||
this.body = 'Page Not Found';
|
||||
ctx.type = 'text';
|
||||
ctx.body = 'Page Not Found';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue