-
Notifications
You must be signed in to change notification settings - Fork 7
/
contentstackError.js
43 lines (36 loc) · 1.09 KB
/
contentstackError.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
export default function error (errorResponse) {
const config = errorResponse.config
const response = errorResponse.response
if (!config || !response) {
throw errorResponse
}
const data = response.data
var errorDetails = {
status: response.status,
statusText: response.statusText
}
if (config.headers && config.headers.authtoken) {
const token = `...${config.headers.authtoken.substr(-5)}`
config.headers.authtoken = token
}
if (config.headers && config.headers.authorization) {
const token = `...${config.headers.authorization.substr(-5)}`
config.headers.authorization = token
}
errorDetails.request = {
url: config.url,
method: config.method,
data: config.data,
headers: config.headers
}
if (data) {
errorDetails.errorMessage = data.error_message || data.message || ''
errorDetails.errorCode = data.error_code || 0
errorDetails.errors = data.errors || {}
errorDetails.error = data.error || ''
}
var error = new Error()
Object.assign(error, errorDetails)
error.message = JSON.stringify(errorDetails)
throw error
}