-
Notifications
You must be signed in to change notification settings - Fork 12
/
is-api-error.ts
37 lines (32 loc) · 900 Bytes
/
is-api-error.ts
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
module.exports = (name, action, log, window) => errInfo => {
const { err, data } = errInfo;
const { result, status, console } = data;
let res;
let errMsg;
if (err) {
const errtext = err.code ? err.code + " " + err.message : err;
errMsg = `${name} ${action}: ${errtext}`;
log(errMsg);
window.showErrorMessage(errMsg);
return true;
}
if (!data || !status || !(status.errors instanceof Array)) {
errMsg = `Unknown response from ${name} ${action}: ${JSON.stringify(res)}`;
log(errMsg);
window.showErrorMessage(errMsg);
return true;
}
if (result && result.status) {
log(result.status);
window.showErrorMessage(result.status);
return true;
}
if (status.errors.length !== 0) {
errMsg = `${name} ${action}:`;
log(errMsg);
window.showErrorMessage(errMsg);
console.forEach(log);
return true;
}
return false;
};