1 | ;
|
2 |
|
3 | function toError() {
|
4 | return async (ctx, next) => {
|
5 | await next();
|
6 |
|
7 | if (ctx.res.statusCode >= 400) {
|
8 | const err = new Error('something bad happend.');
|
9 | err.statusCode = ctx.res.statusCode;
|
10 | err.headers = ctx.res.headers;
|
11 | throw err;
|
12 | }
|
13 | };
|
14 | }
|
15 |
|
16 | module.exports = toError;
|