-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMPError.ts
122 lines (112 loc) · 2.7 KB
/
MPError.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* A class of errors that can occur when using the MapsIndoors SDK.
*
* @export
* @class MPError
* @typedef {MPError}
*/
export default class MPError {
/**
* Occurs when an internet connection is required, or if the content server is unresponsive.
*
* @static
* @readonly
* @type {number}
*/
static readonly networkError: number = 10;
/**
* Occurs if an unknown exception is caught.
*
* @static
* @readonly
* @type {number}
*/
static readonly unknownError: number = 20;
/**
* Occurs if some functions are called before the SDK has been initialized.
*
* @static
* @readonly
* @type {number}
*/
static readonly sdkNotInitialized: number = 22;
/**
* Occurs if the supplied API key is not a valid MapsIndoors key.
*
* @static
* @readonly
* @type {number}
*/
static readonly invalidApiKey: number = 100;
/**
* Creates an instance of MPError.
*
* @constructor
* @param {number} code The errors code, this will be a MapsIndoors error code.
*
* If unsure of the code, check the native SDK.
*
* @param {string} message A descriptive message of what caused the error.
* @param {?number} [status] An optional status code, this will in case of network issues be the response code.
* @param {?*} [tag] Optional object tag.
*/
constructor(
public readonly code: number,
public readonly message: string,
public readonly status?: number,
public readonly tag?: any,
) { }
/**
* Creator for MPError, used to decode JSON from the MapsIndoors SDK.
*
* @public
* @static
* @param {MPErrorParams} object
* @returns {MPError}
*/
public static create(object: MPErrorParams): MPError {
return new MPError(
object.code,
object.message,
object?.status,
object?.tag
);
}
public static parse(error: Error): MPError {
return MPError.create(JSON.parse(error.message))
}
}
/**
* Parameter interface for {@link MPError}.
*
* @interface MPErrorParams
* @typedef {MPErrorParams}
*/
interface MPErrorParams {
/**
* The errors code, this will be a MapsIndoors error code.
*
* If unsure of the code, check the native SDK.
*
* @type {number}
*/
code: number,
/**
* A descriptive message of what caused the error.
*
* @type {string}
*/
message: string,
/**
* An optional status code, this will in case of network issues be the response code.
*
* @type {?number}
*/
status?: number,
/**
* Optional object tag.
*
* @type {?*}
*/
tag?: any,
}