UNPKG

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