-
Notifications
You must be signed in to change notification settings - Fork 30
/
utils.js
41 lines (38 loc) · 998 Bytes
/
utils.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
'use strict';
import _ from 'lodash';
function DestinyError(message) {
Error.call(this);
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name; // function name as error name
this.message = message;
}
export const UTILS = {
indentity: x => x,
noop: () => {},
error: message => {
throw new DestinyError(message);
},
assignMap: obj => _.partialRight(_.assign, obj),
json: res => res.json(),
unwrapDestinyResponse: res => {
if (res.Response && res.Response.data) {
return res.Response.data;
} else if (res.Response) {
return res.Response;
} else {
return res;
}
},
METHODS: [
'POST',
'GET'
]
.reduce((fold, method) => {
fold[method] = method;
return fold;
}, {}),
HEADERS: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
};