JSPM

is-ok

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 17
  • Score
    100M100P100Q55235F
  • License MIT

Check if a HTTP response is successful

Package Exports

  • is-ok

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (is-ok) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

is-ok Build Status

Check if a HTTP response is successful.

npm install is-ok

Usage

Used together with request or the built-in http module.

Accepts a response object, with a statusCode property, as first argument and returns true if the status code was within the 2xx range, otherwise it returns false.

Optionally it takse a callback as second argument, which is called with an error object only if the response was non-successful. The error has statusCode, headers and body properties set, copied from the response.

var request = require('request');
var isOk = require('is-ok');

var fetch = function(url, callback) {
    request.get(url, function(err, response, body) {
        if(err) return callback(err);
        if(!isOk(response, callback)) return;

        callback(null, body);
    });
}

License

MIT