/kwest-handle-error

Reject responses with a bad status

Primary LanguageJavaScript

kwest-handle-error Build Status Dependency Status

Error handler middleware for kwest module. Rejects responses with bad statuscodes.

Installation

$ npm install --save kwest-handle-error

Use

without errorHandler

var request = require('kwest-base');

request('http://www.example.com/not-found')
  .then(function (res) {
    console.log(res.statusCode); // 404
  });

with errorHandler

var handleError = require('kwest-handle-error'),
    kwest       = require('kwest-base'),
    request     = kwest.wrap(handleError());

request('http://www.example.com/not-found')
  .catch(function (err) {
    console.log(err.message); // "404: Not found"
  });