-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.ts
41 lines (39 loc) · 1.42 KB
/
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
38
39
40
41
import { ELocaleKey, tt } from "../../lingos";
import { Utils } from "../utils";
class ErrorHelper {
static getHeader(error: any): string {
if (typeof error == "string") {
//string error (UI state)
return error;
} else if (typeof error == "number") {
//API errorCode
// const errorStrings = lingos.core.errorCode as any;
// if (errorStrings.hasOwnProperty(`err${error}`)) {
// return errorStrings[`err${error}`];
// } else {
return `An unexpected error has occurred. Please try again later.`;
// }
} else if (error && error.toString) {
//native error
return error.toString();
} else {
return `An unknown error has occurred`;
}
}
static toString(error: any): string {
if (typeof error == "string") {
//string error (UI state)
return error;
} else if (typeof error == "number") {
//API errorCode
const errorStrings = tt(Utils.get(ELocaleKey, `ERROR_MSG_${error}`, ELocaleKey.ERROR_MSG_GENERAL));
return errorStrings;
} else if (error && error.toString) {
//native error
return error.toString();
} else {
return `An unknown error has occurred`;
}
}
}
export default ErrorHelper;