UNPKG

rest-boubou

Version:

RESTful HTTP client library

48 lines (40 loc) 1.07 kB
/* * Copyright 2012-2013 the original author or authors * @license MIT, see LICENSE.txt for details * * @author Scott Andrews */ (function (define) { 'use strict'; define(function (require) { var interceptor, when; interceptor = require('../interceptor'); when = require('when'); /** * Rejects the response promise based on the status code. * * Codes greater than or equal to the provided value are rejected. Default * value 400. * * @param {Client} [client] client to wrap * @param {number} [config.code=400] code to indicate a rejection * * @returns {Client} */ return interceptor({ init: function (config) { config.code = config.code || 400; return config; }, response: function (response, config) { if (response.status && response.status.code >= config.code) { return when.reject(response); } return response; } }); }); }( typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); } // Boilerplate for AMD and Node ));