@bbc/http-transport-to-error
v2.2.2
Published
Converts 4XX and 5XX responses to errors
Downloads
2,028
Maintainers
Keywords
Readme
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