UNPKG

6.2 kBPlain TextView Raw
1// Descriptive error types for common issues which may arise
2// during the operation of BitGoJS or BitGoExpress
3
4// Each subclass needs the explicit Object.setPrototypeOf() so that instanceof will work correctly.
5// See https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
6
7export class BitGoJsError extends Error {
8 public constructor(message?: string) {
9 super(message);
10 if (typeof Error.captureStackTrace === 'function') {
11 Error.captureStackTrace(this);
12 }
13 Object.setPrototypeOf(this, BitGoJsError.prototype);
14 }
15}
16
17export class TlsConfigurationError extends BitGoJsError {
18 public constructor(message?: string) {
19 super(message || 'TLS is configuration is invalid');
20 Object.setPrototypeOf(this, TlsConfigurationError.prototype);
21 }
22}
23
24export class NodeEnvironmentError extends BitGoJsError {
25 public constructor(message?: string) {
26 super(message || 'NODE_ENV is invalid for the current bitgo environment');
27 Object.setPrototypeOf(this, NodeEnvironmentError.prototype);
28 }
29}
30
31export class UnsupportedCoinError extends BitGoJsError {
32 public constructor(coin: string) {
33 super(`Coin or token type ${coin} not supported or not compiled. Please be sure that you are using the latest version of BitGoJS.`);
34 Object.setPrototypeOf(this, UnsupportedCoinError.prototype);
35 }
36}
37
38export class AddressTypeChainMismatchError extends BitGoJsError {
39 constructor(addressType: string, chain: number | string) {
40 super(`address type ${addressType} does not correspond to chain ${chain}`);
41 Object.setPrototypeOf(this, AddressTypeChainMismatchError.prototype);
42 }
43}
44
45export class P2shP2wshUnsupportedError extends BitGoJsError {
46 constructor(message?: string) {
47 super(message || 'p2shP2wsh not supported by this coin');
48 Object.setPrototypeOf(this, P2shP2wshUnsupportedError.prototype);
49 }
50}
51
52export class P2wshUnsupportedError extends BitGoJsError {
53 public constructor(message?: string) {
54 super(message || 'p2wsh not supported by this coin');
55 Object.setPrototypeOf(this, P2wshUnsupportedError.prototype);
56 }
57}
58
59export class UnsupportedAddressTypeError extends BitGoJsError {
60 public constructor(message?: string) {
61 super(message || 'invalid address type');
62 Object.setPrototypeOf(this, UnsupportedAddressTypeError.prototype);
63 }
64}
65
66export class InvalidAddressError extends BitGoJsError {
67 public constructor(message?: string) {
68 super(message || 'invalid address');
69 Object.setPrototypeOf(this, InvalidAddressError.prototype);
70 }
71}
72
73export class InvalidAddressVerificationObjectPropertyError extends BitGoJsError {
74 public constructor(message?: string) {
75 super(message || 'address validation failure');
76 Object.setPrototypeOf(this, InvalidAddressVerificationObjectPropertyError.prototype);
77 }
78}
79
80export class UnexpectedAddressError extends BitGoJsError {
81 public constructor(message?: string) {
82 super(message || 'address validation failure');
83 Object.setPrototypeOf(this, UnexpectedAddressError.prototype);
84 }
85}
86
87export class InvalidAddressDerivationPropertyError extends BitGoJsError {
88 public constructor(message?: string) {
89 super(message || 'address chain and/or index are invalid');
90 Object.setPrototypeOf(this, InvalidAddressDerivationPropertyError.prototype);
91 }
92}
93
94export class WalletRecoveryUnsupported extends BitGoJsError {
95 public constructor(message?: string) {
96 super(message || 'wallet recovery is not supported by this coin');
97 Object.setPrototypeOf(this, WalletRecoveryUnsupported.prototype);
98 }
99}
100
101export class MethodNotImplementedError extends BitGoJsError {
102 public constructor(message?: string) {
103 super(message || 'method not implemented');
104 Object.setPrototypeOf(this, MethodNotImplementedError.prototype);
105 }
106}
107
108export class BlockExplorerUnavailable extends BitGoJsError {
109 public constructor(message?: string) {
110 super(message || 'third-party blockexplorer not responding');
111 Object.setPrototypeOf(this, BlockExplorerUnavailable.prototype);
112 }
113}
114
115export class InvalidMemoIdError extends InvalidAddressError {
116 public constructor(message?: string) {
117 super(message || 'invalid memo id');
118 Object.setPrototypeOf(this, InvalidMemoIdError.prototype);
119 }
120}
121
122export class InvalidPaymentIdError extends InvalidAddressError {
123 public constructor(message?: string) {
124 super(message || 'invalid payment id');
125 Object.setPrototypeOf(this, InvalidPaymentIdError.prototype);
126 }
127}
128
129export class KeyRecoveryServiceError extends BitGoJsError {
130 public constructor(message?: string) {
131 super(message || 'key recovery service encountered an error');
132 Object.setPrototypeOf(this, KeyRecoveryServiceError.prototype);
133 }
134}
135
136export class AddressGenerationError extends BitGoJsError {
137 public constructor(message?: string) {
138 super(message || 'address generation failed');
139 Object.setPrototypeOf(this, AddressGenerationError.prototype);
140 }
141}
142
143export class EthereumLibraryUnavailableError extends BitGoJsError {
144 public constructor(packageName: string) {
145 super(`Ethereum library required for operation is not available. Please install "${(packageName)}".`);
146 Object.setPrototypeOf(this, EthereumLibraryUnavailableError.prototype);
147 }
148}
149
150export class StellarFederationUserNotFoundError extends BitGoJsError {
151 public constructor(message?: string) {
152 super(message || 'account not found');
153 Object.setPrototypeOf(this, StellarFederationUserNotFoundError.prototype);
154 }
155}
156
157export class ErrorNoInputToRecover extends BitGoJsError {
158 public constructor(message?: string) {
159 super(message || 'No input to recover - aborting!');
160 Object.setPrototypeOf(this, ErrorNoInputToRecover.prototype);
161 }
162}
163
164export class InvalidKeyPathError extends BitGoJsError {
165 public constructor(keyPath: string) {
166 super(`invalid keypath: ${keyPath}`);
167 Object.setPrototypeOf(this, InvalidKeyPathError.prototype);
168 }
169}
170
171export class InvalidTransactionError extends BitGoJsError {
172 public constructor(message?: string) {
173 super(message || 'Invalid transaction');
174 Object.setPrototypeOf(this, InvalidTransactionError.prototype);
175 }
176}