forked from cujojs/rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrorCode.js
47 lines (40 loc) · 1.05 KB
/
errorCode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* 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
));