@injectivelabs/exceptions 1.15.0 → 1.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/exceptions/base.d.ts +76 -0
- package/dist/cjs/exceptions/base.js +175 -0
- package/dist/cjs/exceptions/exceptions/BitGetException.d.ts +7 -0
- package/dist/cjs/exceptions/exceptions/BitGetException.js +23 -0
- package/dist/cjs/exceptions/exceptions/CosmosWalletException.d.ts +7 -0
- package/dist/cjs/exceptions/exceptions/CosmosWalletException.js +16 -0
- package/dist/cjs/exceptions/exceptions/GeneralException.d.ts +5 -0
- package/dist/cjs/exceptions/exceptions/GeneralException.js +11 -0
- package/dist/cjs/exceptions/exceptions/GrpcUnaryRequestException.d.ts +7 -0
- package/dist/cjs/exceptions/exceptions/GrpcUnaryRequestException.js +21 -0
- package/dist/cjs/exceptions/exceptions/HttpRequestException.d.ts +10 -0
- package/dist/cjs/exceptions/exceptions/HttpRequestException.js +21 -0
- package/dist/cjs/exceptions/exceptions/LedgerCosmosException.d.ts +7 -0
- package/dist/cjs/exceptions/exceptions/LedgerCosmosException.js +40 -0
- package/dist/cjs/exceptions/exceptions/LedgerException.d.ts +7 -0
- package/dist/cjs/exceptions/exceptions/LedgerException.js +40 -0
- package/dist/cjs/exceptions/exceptions/MetamaskException.d.ts +7 -0
- package/dist/cjs/exceptions/exceptions/MetamaskException.js +23 -0
- package/dist/cjs/exceptions/exceptions/OkxWalletException.d.ts +7 -0
- package/dist/cjs/exceptions/exceptions/OkxWalletException.js +23 -0
- package/dist/cjs/exceptions/exceptions/TransactionException.d.ts +7 -0
- package/dist/cjs/exceptions/exceptions/TransactionException.js +26 -0
- package/dist/cjs/exceptions/exceptions/TrezorException.d.ts +7 -0
- package/dist/cjs/exceptions/exceptions/TrezorException.js +16 -0
- package/dist/cjs/exceptions/exceptions/TrustWalletException.d.ts +7 -0
- package/dist/cjs/exceptions/exceptions/TrustWalletException.js +25 -0
- package/dist/cjs/exceptions/exceptions/WalletException.d.ts +5 -0
- package/dist/cjs/exceptions/exceptions/WalletException.js +11 -0
- package/dist/cjs/exceptions/exceptions/Web3Exception.d.ts +7 -0
- package/dist/cjs/exceptions/exceptions/Web3Exception.js +16 -0
- package/dist/cjs/exceptions/exceptions/index.d.ts +15 -0
- package/dist/cjs/exceptions/exceptions/index.js +31 -0
- package/dist/cjs/exceptions/index.d.ts +2 -0
- package/dist/cjs/exceptions/index.js +18 -0
- package/dist/cjs/exceptions/messages.d.ts +12 -0
- package/dist/cjs/exceptions/messages.js +1600 -0
- package/dist/cjs/exceptions/types/codes.d.ts +424 -0
- package/dist/cjs/exceptions/types/codes.js +791 -0
- package/dist/cjs/exceptions/types/context.d.ts +85 -0
- package/dist/cjs/exceptions/types/context.js +23 -0
- package/dist/cjs/exceptions/types/index.d.ts +3 -0
- package/dist/cjs/exceptions/types/index.js +19 -0
- package/dist/cjs/exceptions/types/modules.d.ts +59 -0
- package/dist/cjs/exceptions/types/modules.js +66 -0
- package/dist/cjs/exceptions/utils/grpc.d.ts +3 -0
- package/dist/cjs/exceptions/utils/grpc.js +40 -0
- package/dist/cjs/exceptions/utils/helpers.d.ts +1 -0
- package/dist/cjs/exceptions/utils/helpers.js +24 -0
- package/dist/cjs/exceptions/utils/maps.d.ts +13 -0
- package/dist/cjs/exceptions/utils/maps.js +132 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types.d.ts +2 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils.d.ts +8 -0
- package/dist/cjs/utils.js +47 -0
- package/dist/esm/exceptions/base.d.ts +76 -0
- package/dist/esm/exceptions/base.js +171 -0
- package/dist/esm/exceptions/exceptions/BitGetException.d.ts +7 -0
- package/dist/esm/exceptions/exceptions/BitGetException.js +19 -0
- package/dist/esm/exceptions/exceptions/CosmosWalletException.d.ts +7 -0
- package/dist/esm/exceptions/exceptions/CosmosWalletException.js +12 -0
- package/dist/esm/exceptions/exceptions/GeneralException.d.ts +5 -0
- package/dist/esm/exceptions/exceptions/GeneralException.js +7 -0
- package/dist/esm/exceptions/exceptions/GrpcUnaryRequestException.d.ts +7 -0
- package/dist/esm/exceptions/exceptions/GrpcUnaryRequestException.js +17 -0
- package/dist/esm/exceptions/exceptions/HttpRequestException.d.ts +10 -0
- package/dist/esm/exceptions/exceptions/HttpRequestException.js +17 -0
- package/dist/esm/exceptions/exceptions/LedgerCosmosException.d.ts +7 -0
- package/dist/esm/exceptions/exceptions/LedgerCosmosException.js +36 -0
- package/dist/esm/exceptions/exceptions/LedgerException.d.ts +7 -0
- package/dist/esm/exceptions/exceptions/LedgerException.js +36 -0
- package/dist/esm/exceptions/exceptions/MetamaskException.d.ts +7 -0
- package/dist/esm/exceptions/exceptions/MetamaskException.js +19 -0
- package/dist/esm/exceptions/exceptions/OkxWalletException.d.ts +7 -0
- package/dist/esm/exceptions/exceptions/OkxWalletException.js +19 -0
- package/dist/esm/exceptions/exceptions/TransactionException.d.ts +7 -0
- package/dist/esm/exceptions/exceptions/TransactionException.js +22 -0
- package/dist/esm/exceptions/exceptions/TrezorException.d.ts +7 -0
- package/dist/esm/exceptions/exceptions/TrezorException.js +12 -0
- package/dist/esm/exceptions/exceptions/TrustWalletException.d.ts +7 -0
- package/dist/esm/exceptions/exceptions/TrustWalletException.js +21 -0
- package/dist/esm/exceptions/exceptions/WalletException.d.ts +5 -0
- package/dist/esm/exceptions/exceptions/WalletException.js +7 -0
- package/dist/esm/exceptions/exceptions/Web3Exception.d.ts +7 -0
- package/dist/esm/exceptions/exceptions/Web3Exception.js +12 -0
- package/dist/esm/exceptions/exceptions/index.d.ts +15 -0
- package/dist/esm/exceptions/exceptions/index.js +15 -0
- package/dist/esm/exceptions/index.d.ts +2 -0
- package/dist/esm/exceptions/index.js +2 -0
- package/dist/esm/exceptions/messages.d.ts +12 -0
- package/dist/esm/exceptions/messages.js +1597 -0
- package/dist/esm/exceptions/types/codes.d.ts +424 -0
- package/dist/esm/exceptions/types/codes.js +787 -0
- package/dist/esm/exceptions/types/context.d.ts +85 -0
- package/dist/esm/exceptions/types/context.js +20 -0
- package/dist/esm/exceptions/types/index.d.ts +3 -0
- package/dist/esm/exceptions/types/index.js +3 -0
- package/dist/esm/exceptions/types/modules.d.ts +59 -0
- package/dist/esm/exceptions/types/modules.js +63 -0
- package/dist/esm/exceptions/utils/grpc.d.ts +3 -0
- package/dist/esm/exceptions/utils/grpc.js +3 -0
- package/dist/esm/exceptions/utils/helpers.d.ts +1 -0
- package/dist/esm/exceptions/utils/helpers.js +20 -0
- package/dist/esm/exceptions/utils/maps.d.ts +13 -0
- package/dist/esm/exceptions/utils/maps.js +125 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/types.d.ts +2 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.d.ts +8 -0
- package/dist/esm/utils.js +42 -0
- package/package.json +2 -2
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
2
|
+
import { ErrorType, UnspecifiedErrorCode, } from './types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* we have to define it here as
|
|
5
|
+
* well as in @injectivelabs/utils as that package is
|
|
6
|
+
* importing the exceptions package
|
|
7
|
+
* */
|
|
8
|
+
const toPascalCase = (str) => {
|
|
9
|
+
return `${str}`
|
|
10
|
+
.toLowerCase()
|
|
11
|
+
.replace(new RegExp(/[-_]+/, 'g'), ' ')
|
|
12
|
+
.replace(new RegExp(/[^\w\s]/, 'g'), '')
|
|
13
|
+
.replace(new RegExp(/\s+(.)(\w*)/, 'g'), (_$1, $2, $3) => `${$2.toUpperCase() + $3}`)
|
|
14
|
+
.replace(new RegExp(/\w/), (s) => s.toUpperCase());
|
|
15
|
+
};
|
|
16
|
+
export class ConcreteException extends Error {
|
|
17
|
+
/**
|
|
18
|
+
* The type of the Error
|
|
19
|
+
*/
|
|
20
|
+
type = ErrorType.Unspecified;
|
|
21
|
+
/**
|
|
22
|
+
* Error specific code (HttpStatus, GrpcStatus, etc)
|
|
23
|
+
*/
|
|
24
|
+
code = UnspecifiedErrorCode;
|
|
25
|
+
/**
|
|
26
|
+
* The name of the error (the name of the instance of the Exception)
|
|
27
|
+
*/
|
|
28
|
+
name;
|
|
29
|
+
/**
|
|
30
|
+
* The name of the error (the name of the instance of the Exception)
|
|
31
|
+
* Needed for reporting reasons, ex: bugsnag
|
|
32
|
+
*/
|
|
33
|
+
errorClass;
|
|
34
|
+
/**
|
|
35
|
+
* Providing more context
|
|
36
|
+
* (ex: endpoint on http request)
|
|
37
|
+
*/
|
|
38
|
+
context;
|
|
39
|
+
/**
|
|
40
|
+
* Providing more context as to where the exception was thrown
|
|
41
|
+
* (ex: on-chain module, etc)
|
|
42
|
+
*/
|
|
43
|
+
contextModule;
|
|
44
|
+
/**
|
|
45
|
+
* Providing more context as to why the exception was thrown
|
|
46
|
+
* (ex: on-chain error code, etc)
|
|
47
|
+
*/
|
|
48
|
+
contextCode;
|
|
49
|
+
/**
|
|
50
|
+
* Parsed message of the exception
|
|
51
|
+
*/
|
|
52
|
+
message = '';
|
|
53
|
+
/**
|
|
54
|
+
* The original stack of the error
|
|
55
|
+
*/
|
|
56
|
+
stack = '';
|
|
57
|
+
/**
|
|
58
|
+
* The original message of the error
|
|
59
|
+
*/
|
|
60
|
+
originalMessage = '';
|
|
61
|
+
constructor(error, context) {
|
|
62
|
+
super(error.message);
|
|
63
|
+
this.parseError(error);
|
|
64
|
+
this.parseContext(context);
|
|
65
|
+
this.parse();
|
|
66
|
+
}
|
|
67
|
+
parse() {
|
|
68
|
+
//
|
|
69
|
+
}
|
|
70
|
+
parseError(error) {
|
|
71
|
+
this.setStack(error.stack || '');
|
|
72
|
+
this.setMessage(error.message);
|
|
73
|
+
this.originalMessage = error.message;
|
|
74
|
+
}
|
|
75
|
+
parseContext(errorContext) {
|
|
76
|
+
const { contextModule, type, code, context } = errorContext || {
|
|
77
|
+
contextModule: 'Unknown',
|
|
78
|
+
context: 'Unknown',
|
|
79
|
+
code: UnspecifiedErrorCode,
|
|
80
|
+
type: ErrorType.Unspecified,
|
|
81
|
+
};
|
|
82
|
+
this.context = context;
|
|
83
|
+
this.contextModule = contextModule;
|
|
84
|
+
this.type = type || ErrorType.Unspecified;
|
|
85
|
+
this.code = code || UnspecifiedErrorCode;
|
|
86
|
+
}
|
|
87
|
+
setType(type) {
|
|
88
|
+
this.type = type;
|
|
89
|
+
}
|
|
90
|
+
setCode(code) {
|
|
91
|
+
this.code = code;
|
|
92
|
+
}
|
|
93
|
+
setContext(context) {
|
|
94
|
+
this.context = context;
|
|
95
|
+
}
|
|
96
|
+
setOriginalMessage(message) {
|
|
97
|
+
this.originalMessage = message;
|
|
98
|
+
}
|
|
99
|
+
setStack(stack) {
|
|
100
|
+
try {
|
|
101
|
+
this.stack = stack;
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
// throw nothing here
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
setName(name) {
|
|
108
|
+
this.name = name;
|
|
109
|
+
this.errorClass = name;
|
|
110
|
+
super.name = name;
|
|
111
|
+
}
|
|
112
|
+
setMessage(message) {
|
|
113
|
+
this.message = message;
|
|
114
|
+
super.message = message;
|
|
115
|
+
}
|
|
116
|
+
setContextModule(contextModule) {
|
|
117
|
+
this.contextModule = contextModule;
|
|
118
|
+
}
|
|
119
|
+
setContextCode(code) {
|
|
120
|
+
this.contextCode = code;
|
|
121
|
+
}
|
|
122
|
+
toOriginalError() {
|
|
123
|
+
const error = new Error(this.originalMessage);
|
|
124
|
+
error.stack = this.stack;
|
|
125
|
+
error.name = this.name || '';
|
|
126
|
+
return error;
|
|
127
|
+
}
|
|
128
|
+
toError() {
|
|
129
|
+
const error = new Error(this.message);
|
|
130
|
+
error.stack = this.stack;
|
|
131
|
+
error.name = this.name || '';
|
|
132
|
+
return error;
|
|
133
|
+
}
|
|
134
|
+
toCompactError() {
|
|
135
|
+
const name = this.name || toPascalCase(this.type);
|
|
136
|
+
const error = new Error(`${this.message} | ${JSON.stringify({
|
|
137
|
+
type: this.type,
|
|
138
|
+
code: this.code,
|
|
139
|
+
errorClass: name,
|
|
140
|
+
message: this.message,
|
|
141
|
+
context: this.context,
|
|
142
|
+
contextCode: this.contextCode,
|
|
143
|
+
contextModule: this.contextModule,
|
|
144
|
+
originalMessage: this.originalMessage,
|
|
145
|
+
stack: (this.stack || '').split('\n').map((line) => line.trim()),
|
|
146
|
+
})}`);
|
|
147
|
+
error.stack = this.stack;
|
|
148
|
+
error.name = this.name || toPascalCase(this.type);
|
|
149
|
+
return error;
|
|
150
|
+
}
|
|
151
|
+
toJson() {
|
|
152
|
+
return JSON.stringify({ error: this.message, stack: this.stack });
|
|
153
|
+
}
|
|
154
|
+
toObject() {
|
|
155
|
+
const name = this.name || toPascalCase(this.type);
|
|
156
|
+
return {
|
|
157
|
+
code: this.code,
|
|
158
|
+
type: this.type,
|
|
159
|
+
errorClass: name,
|
|
160
|
+
message: this.message,
|
|
161
|
+
context: this.context,
|
|
162
|
+
contextCode: this.contextCode,
|
|
163
|
+
contextModule: this.contextModule,
|
|
164
|
+
originalMessage: this.originalMessage,
|
|
165
|
+
stack: (this.stack || '').split('\n').map((line) => line.trim()),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
toString() {
|
|
169
|
+
return this.message;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorContext } from '../types/index.js';
|
|
3
|
+
export declare class BitGetException extends ConcreteException {
|
|
4
|
+
static errorClass: string;
|
|
5
|
+
constructor(error: Error, context?: ErrorContext);
|
|
6
|
+
parse(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType } from '../types/index.js';
|
|
3
|
+
import { mapMetamaskMessage } from '../utils/maps.js';
|
|
4
|
+
const removeBitGetFromErrorString = (message) => message
|
|
5
|
+
.replaceAll('BitGet', '')
|
|
6
|
+
.replaceAll('Bitget:', '')
|
|
7
|
+
.replaceAll('Bitkeep:', '');
|
|
8
|
+
export class BitGetException extends ConcreteException {
|
|
9
|
+
static errorClass = 'BitGetException';
|
|
10
|
+
constructor(error, context) {
|
|
11
|
+
super(error, context);
|
|
12
|
+
this.type = ErrorType.WalletError;
|
|
13
|
+
}
|
|
14
|
+
parse() {
|
|
15
|
+
const { message } = this;
|
|
16
|
+
this.setName(BitGetException.errorClass);
|
|
17
|
+
this.setMessage(mapMetamaskMessage(removeBitGetFromErrorString(message)));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorContext } from '../types/index.js';
|
|
3
|
+
export declare class CosmosWalletException extends ConcreteException {
|
|
4
|
+
static errorClass: string;
|
|
5
|
+
constructor(error: Error, context?: ErrorContext);
|
|
6
|
+
parse(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType } from '../types/index.js';
|
|
3
|
+
export class CosmosWalletException extends ConcreteException {
|
|
4
|
+
static errorClass = 'CosmosWalletException';
|
|
5
|
+
constructor(error, context) {
|
|
6
|
+
super(error, context);
|
|
7
|
+
this.type = ErrorType.WalletError;
|
|
8
|
+
}
|
|
9
|
+
parse() {
|
|
10
|
+
this.setName(CosmosWalletException.errorClass);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorContext } from '../types/index.js';
|
|
3
|
+
export declare class GrpcUnaryRequestException extends ConcreteException {
|
|
4
|
+
static errorClass: string;
|
|
5
|
+
constructor(error: Error, context?: ErrorContext);
|
|
6
|
+
parse(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType, GRPC_REQUEST_FAILED } from '../types/index.js';
|
|
3
|
+
export class GrpcUnaryRequestException extends ConcreteException {
|
|
4
|
+
static errorClass = 'GrpcUnaryRequestException';
|
|
5
|
+
constructor(error, context) {
|
|
6
|
+
super(error, context);
|
|
7
|
+
this.type = ErrorType.GrpcUnaryRequest;
|
|
8
|
+
}
|
|
9
|
+
parse() {
|
|
10
|
+
const { message } = this;
|
|
11
|
+
if (message.toLowerCase().includes('response closed without headers')) {
|
|
12
|
+
this.setMessage('The request has failed. The server has closed the connection without sending any headers.');
|
|
13
|
+
this.setContextCode(GRPC_REQUEST_FAILED);
|
|
14
|
+
}
|
|
15
|
+
this.setName(GrpcUnaryRequestException.errorClass);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorContext, HttpRequestMethod } from '../types/index.js';
|
|
3
|
+
export declare class HttpRequestException extends ConcreteException {
|
|
4
|
+
static errorClass: string;
|
|
5
|
+
method: HttpRequestMethod;
|
|
6
|
+
constructor(error: Error, context?: ErrorContext & {
|
|
7
|
+
method?: HttpRequestMethod;
|
|
8
|
+
});
|
|
9
|
+
parse(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType, HttpRequestMethod } from '../types/index.js';
|
|
3
|
+
export class HttpRequestException extends ConcreteException {
|
|
4
|
+
static errorClass = 'HttpRequestException';
|
|
5
|
+
method = HttpRequestMethod.Get;
|
|
6
|
+
constructor(error, context) {
|
|
7
|
+
super(error, context);
|
|
8
|
+
this.type = ErrorType.HttpRequest;
|
|
9
|
+
this.method = context
|
|
10
|
+
? context.method || HttpRequestMethod.Get
|
|
11
|
+
: HttpRequestMethod.Get;
|
|
12
|
+
this.context = context?.context || 'Unknown';
|
|
13
|
+
}
|
|
14
|
+
parse() {
|
|
15
|
+
this.setName(HttpRequestException.errorClass);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorContext } from '../types/index.js';
|
|
3
|
+
export declare class LedgerCosmosException extends ConcreteException {
|
|
4
|
+
static errorClass: string;
|
|
5
|
+
constructor(error: Error, context?: ErrorContext);
|
|
6
|
+
parse(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType } from '../types/index.js';
|
|
3
|
+
import { isCommonLockedError } from '../utils/helpers.js';
|
|
4
|
+
export class LedgerCosmosException extends ConcreteException {
|
|
5
|
+
static errorClass = 'LedgerCosmosException';
|
|
6
|
+
constructor(error, context) {
|
|
7
|
+
super(error, context);
|
|
8
|
+
this.type = ErrorType.WalletError;
|
|
9
|
+
}
|
|
10
|
+
parse() {
|
|
11
|
+
const { message } = this;
|
|
12
|
+
if (isCommonLockedError(message)) {
|
|
13
|
+
this.setMessage('Please ensure your Ledger is connected, unlocked and your Cosmos app is open.');
|
|
14
|
+
}
|
|
15
|
+
if (message.includes('No device selected.')) {
|
|
16
|
+
this.setMessage('Please make sure your Ledger device is connected, unlocked and your Cosmos app is open');
|
|
17
|
+
}
|
|
18
|
+
if (message.includes('Unable to set device configuration.')) {
|
|
19
|
+
this.setMessage('Please restart your Ledger device and try connecting again');
|
|
20
|
+
}
|
|
21
|
+
if (message.includes('Cannot read properties of undefined')) {
|
|
22
|
+
this.setMessage('Please make sure your Ledger device is connected');
|
|
23
|
+
}
|
|
24
|
+
if (message.toLowerCase().includes('locked')) {
|
|
25
|
+
this.setMessage('Please make sure your Ledger device is connected, unlocked and your Cosmos app is open');
|
|
26
|
+
}
|
|
27
|
+
if (message.includes('Condition of use not satisfied') ||
|
|
28
|
+
message.includes('0x6985')) {
|
|
29
|
+
this.setMessage('The request has been rejected');
|
|
30
|
+
}
|
|
31
|
+
if (message.includes('U2F browser support is needed for Ledger.')) {
|
|
32
|
+
this.setMessage('Please use the latest Chrome/Firefox browser versions to connect with your Ledger device');
|
|
33
|
+
}
|
|
34
|
+
this.setName(LedgerCosmosException.errorClass);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorContext } from '../types/index.js';
|
|
3
|
+
export declare class LedgerException extends ConcreteException {
|
|
4
|
+
static errorClass: string;
|
|
5
|
+
constructor(error: Error, context?: ErrorContext);
|
|
6
|
+
parse(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType } from '../types/index.js';
|
|
3
|
+
import { isCommonLockedError } from '../utils/helpers.js';
|
|
4
|
+
export class LedgerException extends ConcreteException {
|
|
5
|
+
static errorClass = 'LedgerException';
|
|
6
|
+
constructor(error, context) {
|
|
7
|
+
super(error, context);
|
|
8
|
+
this.type = ErrorType.WalletError;
|
|
9
|
+
}
|
|
10
|
+
parse() {
|
|
11
|
+
const { message } = this;
|
|
12
|
+
if (isCommonLockedError(message)) {
|
|
13
|
+
this.setMessage('Please ensure your Ledger is connected, unlocked and your Ethereum app is open.');
|
|
14
|
+
}
|
|
15
|
+
if (message.includes('No device selected.')) {
|
|
16
|
+
this.setMessage('Please make sure your Ledger device is connected, unlocked and your Ethereum app is open');
|
|
17
|
+
}
|
|
18
|
+
if (message.includes('Unable to set device configuration.')) {
|
|
19
|
+
this.setMessage('Please restart your Ledger device and try connecting again');
|
|
20
|
+
}
|
|
21
|
+
if (message.includes('Cannot read properties of undefined')) {
|
|
22
|
+
this.setMessage('Please make sure your Ledger device is connected');
|
|
23
|
+
}
|
|
24
|
+
if (message.toLowerCase().includes('locked')) {
|
|
25
|
+
this.setMessage('Please make sure your Ledger device is connected, unlocked and your Ethereum app is open');
|
|
26
|
+
}
|
|
27
|
+
if (message.includes('Condition of use not satisfied') ||
|
|
28
|
+
message.includes('0x6985')) {
|
|
29
|
+
this.setMessage('The request has been rejected');
|
|
30
|
+
}
|
|
31
|
+
if (message.includes('U2F browser support is needed for Ledger.')) {
|
|
32
|
+
this.setMessage('Please use the latest Chrome/Firefox browser versions to connect with your Ledger device');
|
|
33
|
+
}
|
|
34
|
+
this.setName(LedgerException.errorClass);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorContext } from '../types/index.js';
|
|
3
|
+
export declare class MetamaskException extends ConcreteException {
|
|
4
|
+
static errorClass: string;
|
|
5
|
+
constructor(error: Error, context?: ErrorContext);
|
|
6
|
+
parse(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType } from '../types/index.js';
|
|
3
|
+
import { mapMetamaskMessage } from '../utils/maps.js';
|
|
4
|
+
const removeMetamaskFromErrorString = (message) => message
|
|
5
|
+
.replaceAll('Metamask', '')
|
|
6
|
+
.replaceAll('MetaMask', '')
|
|
7
|
+
.replaceAll('Metamask:', '');
|
|
8
|
+
export class MetamaskException extends ConcreteException {
|
|
9
|
+
static errorClass = 'MetamaskException';
|
|
10
|
+
constructor(error, context) {
|
|
11
|
+
super(error, context);
|
|
12
|
+
this.type = ErrorType.WalletError;
|
|
13
|
+
}
|
|
14
|
+
parse() {
|
|
15
|
+
const { message } = this;
|
|
16
|
+
this.setMessage(mapMetamaskMessage(removeMetamaskFromErrorString(message)));
|
|
17
|
+
this.setName(MetamaskException.errorClass);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorContext } from '../types/index.js';
|
|
3
|
+
export declare class OkxWalletException extends ConcreteException {
|
|
4
|
+
static errorClass: string;
|
|
5
|
+
constructor(error: Error, context?: ErrorContext);
|
|
6
|
+
parse(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType } from '../types/index.js';
|
|
3
|
+
import { mapMetamaskMessage } from '../utils/maps.js';
|
|
4
|
+
const removeOkxWalletFromErrorString = (message) => message
|
|
5
|
+
.replaceAll('OkxWallet', '')
|
|
6
|
+
.replaceAll('Okx', '')
|
|
7
|
+
.replaceAll('OkxWallet:', '');
|
|
8
|
+
export class OkxWalletException extends ConcreteException {
|
|
9
|
+
static errorClass = 'OkxWalletException';
|
|
10
|
+
constructor(error, context) {
|
|
11
|
+
super(error, context);
|
|
12
|
+
this.type = ErrorType.WalletError;
|
|
13
|
+
}
|
|
14
|
+
parse() {
|
|
15
|
+
const { message } = this;
|
|
16
|
+
this.setMessage(mapMetamaskMessage(removeOkxWalletFromErrorString(message)));
|
|
17
|
+
this.setName(OkxWalletException.errorClass);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorContext } from '../types/index.js';
|
|
3
|
+
export declare class TransactionException extends ConcreteException {
|
|
4
|
+
static errorClass: string;
|
|
5
|
+
constructor(error: Error, context?: ErrorContext);
|
|
6
|
+
parse(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType } from '../types/index.js';
|
|
3
|
+
import { mapFailedTransactionMessage, parseErrorMessage } from '../utils/maps.js';
|
|
4
|
+
export class TransactionException extends ConcreteException {
|
|
5
|
+
static errorClass = 'TransactionException';
|
|
6
|
+
constructor(error, context) {
|
|
7
|
+
super(error, context);
|
|
8
|
+
this.type = ErrorType.ChainError;
|
|
9
|
+
}
|
|
10
|
+
parse() {
|
|
11
|
+
const { message, context, contextModule, contextCode } = this;
|
|
12
|
+
const { code, message: parsedMessage, contextModule: parsedContextModule, } = mapFailedTransactionMessage(message, { contextCode, contextModule });
|
|
13
|
+
this.setContext(context || 'Unknown');
|
|
14
|
+
this.setMessage(parsedMessage);
|
|
15
|
+
this.setContextCode(code);
|
|
16
|
+
this.setOriginalMessage(parseErrorMessage(message));
|
|
17
|
+
if (parsedContextModule) {
|
|
18
|
+
this.setContextModule(parsedContextModule);
|
|
19
|
+
}
|
|
20
|
+
this.setName(TransactionException.errorClass);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorContext } from '../types/index.js';
|
|
3
|
+
export declare class TrezorException extends ConcreteException {
|
|
4
|
+
static errorClass: string;
|
|
5
|
+
constructor(error: Error, context?: ErrorContext);
|
|
6
|
+
parse(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType } from '../types/index.js';
|
|
3
|
+
export class TrezorException extends ConcreteException {
|
|
4
|
+
static errorClass = 'TrezorException';
|
|
5
|
+
constructor(error, context) {
|
|
6
|
+
super(error, context);
|
|
7
|
+
this.type = ErrorType.WalletError;
|
|
8
|
+
}
|
|
9
|
+
parse() {
|
|
10
|
+
this.setName(TrezorException.errorClass);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorContext } from '../types/index.js';
|
|
3
|
+
export declare class TrustWalletException extends ConcreteException {
|
|
4
|
+
static errorClass: string;
|
|
5
|
+
constructor(error: Error, context?: ErrorContext);
|
|
6
|
+
parse(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType } from '../types/index.js';
|
|
3
|
+
import { mapMetamaskMessage } from '../utils/maps.js';
|
|
4
|
+
const removeTrustWalletFromErrorString = (message) => message
|
|
5
|
+
.replaceAll('TrustWallet', '')
|
|
6
|
+
.replaceAll('Trust Wallet', '')
|
|
7
|
+
.replaceAll('Trustwallet', '')
|
|
8
|
+
.replaceAll('TrustWallet:', '')
|
|
9
|
+
.replaceAll('Trust Wallet:', '');
|
|
10
|
+
export class TrustWalletException extends ConcreteException {
|
|
11
|
+
static errorClass = 'TrustWalletException';
|
|
12
|
+
constructor(error, context) {
|
|
13
|
+
super(error, context);
|
|
14
|
+
this.type = ErrorType.WalletError;
|
|
15
|
+
}
|
|
16
|
+
parse() {
|
|
17
|
+
const { message } = this;
|
|
18
|
+
this.setMessage(mapMetamaskMessage(removeTrustWalletFromErrorString(message)));
|
|
19
|
+
this.setName(TrustWalletException.errorClass);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConcreteException } from '../base.js';
|
|
2
|
+
import { ErrorType } from '../types/index.js';
|
|
3
|
+
export class Web3Exception extends ConcreteException {
|
|
4
|
+
static errorClass = 'Web3Exception';
|
|
5
|
+
constructor(error, context) {
|
|
6
|
+
super(error, context);
|
|
7
|
+
this.type = ErrorType.Web3;
|
|
8
|
+
}
|
|
9
|
+
parse() {
|
|
10
|
+
this.setName(Web3Exception.errorClass);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GrpcUnaryRequestException } from './GrpcUnaryRequestException.js';
|
|
2
|
+
import { HttpRequestException } from './HttpRequestException.js';
|
|
3
|
+
import { Web3Exception } from './Web3Exception.js';
|
|
4
|
+
import { GeneralException } from './GeneralException.js';
|
|
5
|
+
import { LedgerException } from './LedgerException.js';
|
|
6
|
+
import { LedgerCosmosException } from './LedgerCosmosException.js';
|
|
7
|
+
import { MetamaskException } from './MetamaskException.js';
|
|
8
|
+
import { TrustWalletException } from './TrustWalletException.js';
|
|
9
|
+
import { OkxWalletException } from './OkxWalletException.js';
|
|
10
|
+
import { TrezorException } from './TrezorException.js';
|
|
11
|
+
import { CosmosWalletException } from './CosmosWalletException.js';
|
|
12
|
+
import { TransactionException } from './TransactionException.js';
|
|
13
|
+
import { WalletException } from './WalletException.js';
|
|
14
|
+
import { BitGetException } from './BitGetException.js';
|
|
15
|
+
export { Web3Exception, LedgerException, TrezorException, WalletException, GeneralException, BitGetException, MetamaskException, TransactionException, TrustWalletException, OkxWalletException, HttpRequestException, LedgerCosmosException, CosmosWalletException, GrpcUnaryRequestException, };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GrpcUnaryRequestException } from './GrpcUnaryRequestException.js';
|
|
2
|
+
import { HttpRequestException } from './HttpRequestException.js';
|
|
3
|
+
import { Web3Exception } from './Web3Exception.js';
|
|
4
|
+
import { GeneralException } from './GeneralException.js';
|
|
5
|
+
import { LedgerException } from './LedgerException.js';
|
|
6
|
+
import { LedgerCosmosException } from './LedgerCosmosException.js';
|
|
7
|
+
import { MetamaskException } from './MetamaskException.js';
|
|
8
|
+
import { TrustWalletException } from './TrustWalletException.js';
|
|
9
|
+
import { OkxWalletException } from './OkxWalletException.js';
|
|
10
|
+
import { TrezorException } from './TrezorException.js';
|
|
11
|
+
import { CosmosWalletException } from './CosmosWalletException.js';
|
|
12
|
+
import { TransactionException } from './TransactionException.js';
|
|
13
|
+
import { WalletException } from './WalletException.js';
|
|
14
|
+
import { BitGetException } from './BitGetException.js';
|
|
15
|
+
export { Web3Exception, LedgerException, TrezorException, WalletException, GeneralException, BitGetException, MetamaskException, TransactionException, TrustWalletException, OkxWalletException, HttpRequestException, LedgerCosmosException, CosmosWalletException, GrpcUnaryRequestException, };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ErrorContextCode, TransactionChainErrorModule } from './types/index.js';
|
|
2
|
+
export declare const chainModuleCodeErrorMessagesMap: Record<string, Record<number, string>>;
|
|
3
|
+
/**
|
|
4
|
+
* **Legacy** but needed for error messages from broadcasting transactions
|
|
5
|
+
* where we don't control the response and only have the message
|
|
6
|
+
* i.e Keplr, Leap, etc
|
|
7
|
+
*/
|
|
8
|
+
export declare const chainErrorMessagesMap: Record<string, {
|
|
9
|
+
message: string;
|
|
10
|
+
code: ErrorContextCode;
|
|
11
|
+
module: TransactionChainErrorModule;
|
|
12
|
+
}>;
|