forked from fourTheorem/slic-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxios-util.js
52 lines (45 loc) · 1.45 KB
/
axios-util.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
48
49
50
51
52
import pick from 'lodash/pick.js';
const suppressedProperties = new Set(['nativeProtocols']);
export function toneAxiosError(error) {
if (!process.env.VERBOSE_AXIOS_ERRORS) {
const summarized = {};
// Remove verbose properties from request options
if (error.request) {
summarized.request = pick(error.request, [
'headers',
'method',
'path',
'_header',
]);
/* eslint-disable no-underscore-dangle, no-param-reassign */
if (error.request._options) {
const requestOptions = { ...error.request._options };
for (const property of Object.keys(error.request._options)) {
if (suppressedProperties.has(property)) {
delete requestOptions[property];
}
}
summarized.request = {
_options: requestOptions,
};
}
}
if (error.response) {
summarized.response = pick(error.response, [
'headers',
'status',
'statusText',
'config.url',
'data',
]);
}
error._full_request = error.request;
error._full_response = error.response;
/* eslint-enable no-underscore-dangle, no-param-reassign */
Object.assign(error, summarized);
// Make large objects non-enumerable to remove excessive verbosity from logs
for (const property of ['config', '_full_request', '_full_response'])
Object.defineProperty(error, property, { enumerable: false });
}
return error;
}