UNPKG

316 BJavaScriptView Raw
1'use strict';
2
3function 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
16module.exports = toError;