UNPKG

1.07 kBJavaScriptView Raw
1/*
2 * Copyright 2012-2013 the original author or authors
3 * @license MIT, see LICENSE.txt for details
4 *
5 * @author Scott Andrews
6 */
7
8(function (define) {
9 'use strict';
10
11 define(function (require) {
12
13 var interceptor, when;
14
15 interceptor = require('../interceptor');
16 when = require('when');
17
18 /**
19 * Rejects the response promise based on the status code.
20 *
21 * Codes greater than or equal to the provided value are rejected. Default
22 * value 400.
23 *
24 * @param {Client} [client] client to wrap
25 * @param {number} [config.code=400] code to indicate a rejection
26 *
27 * @returns {Client}
28 */
29 return interceptor({
30 init: function (config) {
31 config.code = config.code || 400;
32 return config;
33 },
34 response: function (response, config) {
35 if (response.status && response.status.code >= config.code) {
36 return when.reject(response);
37 }
38 return response;
39 }
40 });
41
42 });
43
44}(
45 typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }
46 // Boilerplate for AMD and Node
47));