@bbc/http-transport-to-error

2.2.2 • Public • Published

NPM downloads npm license github-issues stars forks

http-transport-to-error

Middleware convert 4XX and 5XX responses to errors

Installation

npm install --save @bbc/http-transport-to-error

Usage

Convert any response equal to or greater than 400 to errors: 

const url = 'http://example.com/404';
const HttpTransport = require('@bbc/http-transport');
const toError = require('@bbc/http-transport-to-error');

const client = HttpTransport.createBuilder()
   .use(toError())
   .createClient();

  try {
    await client.get(url).asResponse();
  } catch (err) {
    console.error(err);    
  }
});

Test

npm test

To generate a test coverage report:

npm run coverage

/@bbc/http-transport-to-error/

    Package Sidebar

    Install

    npm i @bbc/http-transport-to-error

    Weekly Downloads

    215

    Version

    2.2.2

    License

    Apache-2.0

    Unpacked Size

    5.55 kB

    Total Files

    9

    Last publish

    Collaborators

    • alexshelley
    • oliviadrury
    • brotherkaif
    • kieranjoyce
    • monsai
    • rosemcnally
    • felixmercermoss
    • katyasa
    • dwalker487
    • amitsavant
    • remotecharms
    • npmbs
    • vaughr03
    • iuketaylor
    • jamiebower185
    • benjwheeler
    • onlyonehas
    • drrobharper
    • johnnewman
    • ibl
    • simontanner
    • simongregory
    • tonymcbeth