@bbc/http-transport-to-error

Converts 4XX and 5XX responses to errors

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@bbc/http-transport-to-error
052.1.14 years ago5 years agoMinified + gzip package size for @bbc/http-transport-to-error in KB

Readme

NPM downloads Build Status 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