-
Notifications
You must be signed in to change notification settings - Fork 525
/
Copy patherrors.ts
161 lines (144 loc) · 3.54 KB
/
errors.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* eslint-disable max-classes-per-file -- Errors can be defined in the same file */
import { inspect } from 'util'
/**
* Base Error class for xrpl.js. All Errors thrown by xrpl.js should throw
* XrplErrors.
*
* @category Errors
*/
class XrplError extends Error {
public readonly name: string
public readonly message: string
public readonly data?: unknown
/**
* Construct an XrplError.
*
* @param message - The error message.
* @param data - The data that caused the error.
*/
public constructor(message = '', data?: unknown) {
super(message)
this.name = this.constructor.name
this.message = message
this.data = data
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- `captureStackTrace` can be null in browsers
if (Error.captureStackTrace != null) {
Error.captureStackTrace(this, this.constructor)
}
}
/**
* Converts the Error to a human-readable String form.
*
* @returns The String output of the Error.
*/
public toString(): string {
let result = `[${this.name}(${this.message}`
if (this.data) {
result += `, ${inspect(this.data)}`
}
result += ')]'
return result
}
/**
* Console.log in node uses util.inspect on object, and util.inspect allows
* us to customize its output:
* https://nodejs.org/api/util.html#util_custom_inspect_function_on_objects.
*
* @returns The String output of the Error.
*/
public inspect(): string {
return this.toString()
}
}
/**
* Error thrown when rippled responds with an error.
*
* @category Errors
*/
class RippledError extends XrplError {}
/**
* Error thrown when xrpl.js cannot specify error type.
*
* @category Errors
*/
class UnexpectedError extends XrplError {}
/**
* Error thrown when xrpl.js has an error with connection to rippled.
*
* @category Errors
*/
class ConnectionError extends XrplError {}
/**
* Error thrown when xrpl.js is not connected to rippled server.
*
* @category Errors
*/
class NotConnectedError extends ConnectionError {}
/**
* Error thrown when xrpl.js has disconnected from rippled server.
*
* @category Errors
*/
class DisconnectedError extends ConnectionError {}
/**
* Error thrown when rippled is not initialized.
*
* @category Errors
*/
class RippledNotInitializedError extends ConnectionError {}
/**
* Error thrown when xrpl.js times out.
*
* @category Errors
*/
class TimeoutError extends ConnectionError {}
/**
* Error thrown when xrpl.js sees a response in the wrong format.
*
* @category Errors
*/
class ResponseFormatError extends ConnectionError {}
/**
* Error thrown when xrpl.js sees a malformed transaction.
*
* @category Errors
*/
class ValidationError extends XrplError {}
/**
* Error thrown when a client cannot generate a wallet from the testnet/devnet
* faucets, or when the client cannot infer the faucet URL (i.e. when the Client
* is connected to mainnet).
*
* @category Errors
*/
class XRPLFaucetError extends XrplError {}
/**
* Error thrown when xrpl.js cannot retrieve a transaction, ledger, account, etc.
* From rippled.
*
* @category Errors
*/
class NotFoundError extends XrplError {
/**
* Construct an XrplError.
*
* @param message - The error message. Defaults to "Not found".
*/
public constructor(message = 'Not found') {
super(message)
}
}
export {
XrplError,
UnexpectedError,
ConnectionError,
RippledError,
NotConnectedError,
DisconnectedError,
RippledNotInitializedError,
TimeoutError,
ResponseFormatError,
ValidationError,
NotFoundError,
XRPLFaucetError,
}