UNPKG

@bbc/http-transport

Version:

A flexible, modular REST client built for ease-of-use and resilience.

17 lines (13 loc) 317 B
'use strict'; function toError() { return async (ctx, next) => { await next(); if (ctx.res.statusCode >= 400) { const err = new Error('something bad happened.'); err.statusCode = ctx.res.statusCode; err.headers = ctx.res.headers; throw err; } }; } module.exports = toError;