@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,85 @@
|
|
|
1
|
+
import { ErrorCode, ErrorContextCode } from './codes.js';
|
|
2
|
+
export declare enum HttpRequestMethod {
|
|
3
|
+
Get = "GET",
|
|
4
|
+
Post = "POST",
|
|
5
|
+
Options = "OPTIONS"
|
|
6
|
+
}
|
|
7
|
+
export declare enum ErrorType {
|
|
8
|
+
Unspecified = "unspecified",
|
|
9
|
+
ChainError = "chain-error",
|
|
10
|
+
ExecutionError = "execution-error",
|
|
11
|
+
NotFoundError = "not-found-error",
|
|
12
|
+
ValidationError = "validation-error",
|
|
13
|
+
WalletError = "wallet-error",
|
|
14
|
+
WalletNotInstalledError = "wallet-not-installed-error",
|
|
15
|
+
GrpcUnaryRequest = "grpc-unary-request",
|
|
16
|
+
HttpRequest = "http-request",
|
|
17
|
+
Web3 = "web3",
|
|
18
|
+
Web3Gateway = "web3-gateway"
|
|
19
|
+
}
|
|
20
|
+
export interface ErrorContext {
|
|
21
|
+
code?: ErrorCode;
|
|
22
|
+
type?: ErrorType;
|
|
23
|
+
/**
|
|
24
|
+
* Additional context needed for the exception
|
|
25
|
+
*/
|
|
26
|
+
context?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Where is the exception thrown
|
|
29
|
+
*/
|
|
30
|
+
contextModule?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Needed when we get a code error from a Http/Grpc Request
|
|
33
|
+
* and we need to specify the error code for the particular message
|
|
34
|
+
* for example why the transaction has failed
|
|
35
|
+
* */
|
|
36
|
+
contextCode?: ErrorContextCode;
|
|
37
|
+
}
|
|
38
|
+
export interface Exception {
|
|
39
|
+
/**
|
|
40
|
+
* The type of the Error
|
|
41
|
+
*/
|
|
42
|
+
type: ErrorType;
|
|
43
|
+
/**
|
|
44
|
+
* Error specific code (HttpStatus, GrpcStatus, etc)
|
|
45
|
+
*/
|
|
46
|
+
code: ErrorCode;
|
|
47
|
+
/**
|
|
48
|
+
* The name of the error (the name of the instance of the Exception)
|
|
49
|
+
*/
|
|
50
|
+
name: string;
|
|
51
|
+
/**
|
|
52
|
+
* Providing more context as to where the exception was thrown
|
|
53
|
+
* (ex: on-chain module, etc)
|
|
54
|
+
*/
|
|
55
|
+
contextModule?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Providing more context as to why the exception was thrown
|
|
58
|
+
* (ex: on-chain error code, etc)
|
|
59
|
+
*/
|
|
60
|
+
contextCode?: ErrorContextCode;
|
|
61
|
+
/**
|
|
62
|
+
* Parsed message of the exception
|
|
63
|
+
*/
|
|
64
|
+
message: string;
|
|
65
|
+
/**
|
|
66
|
+
* The original stack of the error
|
|
67
|
+
*/
|
|
68
|
+
stack?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The original message of the error
|
|
71
|
+
*/
|
|
72
|
+
originalMessage: string;
|
|
73
|
+
parse?(): void;
|
|
74
|
+
parseError(error: Error): void;
|
|
75
|
+
parseContext(context?: ErrorContext): void;
|
|
76
|
+
setType(type: ErrorType): void;
|
|
77
|
+
setCode(code: ErrorCode): void;
|
|
78
|
+
setStack(stack: string): void;
|
|
79
|
+
setName(name: string): void;
|
|
80
|
+
setMessage(message: string): void;
|
|
81
|
+
setContextModule(contextModule: string): void;
|
|
82
|
+
toOriginalError(): Error;
|
|
83
|
+
toError(): Error;
|
|
84
|
+
toString(): string;
|
|
85
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export var HttpRequestMethod;
|
|
2
|
+
(function (HttpRequestMethod) {
|
|
3
|
+
HttpRequestMethod["Get"] = "GET";
|
|
4
|
+
HttpRequestMethod["Post"] = "POST";
|
|
5
|
+
HttpRequestMethod["Options"] = "OPTIONS";
|
|
6
|
+
})(HttpRequestMethod || (HttpRequestMethod = {}));
|
|
7
|
+
export var ErrorType;
|
|
8
|
+
(function (ErrorType) {
|
|
9
|
+
ErrorType["Unspecified"] = "unspecified";
|
|
10
|
+
ErrorType["ChainError"] = "chain-error";
|
|
11
|
+
ErrorType["ExecutionError"] = "execution-error";
|
|
12
|
+
ErrorType["NotFoundError"] = "not-found-error";
|
|
13
|
+
ErrorType["ValidationError"] = "validation-error";
|
|
14
|
+
ErrorType["WalletError"] = "wallet-error";
|
|
15
|
+
ErrorType["WalletNotInstalledError"] = "wallet-not-installed-error";
|
|
16
|
+
ErrorType["GrpcUnaryRequest"] = "grpc-unary-request";
|
|
17
|
+
ErrorType["HttpRequest"] = "http-request";
|
|
18
|
+
ErrorType["Web3"] = "web3";
|
|
19
|
+
ErrorType["Web3Gateway"] = "web3-gateway";
|
|
20
|
+
})(ErrorType || (ErrorType = {}));
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare enum ContractErrorModule {
|
|
2
|
+
Erc20Contract = "erc20-contract",
|
|
3
|
+
Peggy = "peggy-contract",
|
|
4
|
+
PeggyOld = "peggy-old-contract"
|
|
5
|
+
}
|
|
6
|
+
export declare enum ChainErrorModule {
|
|
7
|
+
Auction = "chain-auction",
|
|
8
|
+
Auth = "chain-auth",
|
|
9
|
+
Authz = "chain-authz",
|
|
10
|
+
Bank = "chain-bank",
|
|
11
|
+
Distribution = "chain-distribution",
|
|
12
|
+
Exchange = "chain-exchange",
|
|
13
|
+
Gov = "chain-gov",
|
|
14
|
+
Ibc = "chain-ibc",
|
|
15
|
+
InsuranceFund = "chain-insurance",
|
|
16
|
+
Mint = "chain-mint",
|
|
17
|
+
Oracle = "chain-oracle",
|
|
18
|
+
Peggy = "chain-peggy",
|
|
19
|
+
Staking = "chain-staking",
|
|
20
|
+
Wasm = "chain-wasm",
|
|
21
|
+
WasmX = "chain-wasmx",
|
|
22
|
+
Tendermint = "chain-tendermint",
|
|
23
|
+
Permissions = "chain-permissions"
|
|
24
|
+
}
|
|
25
|
+
export declare enum IndexerErrorModule {
|
|
26
|
+
Account = "indexer-account",
|
|
27
|
+
Auction = "indexer-auction",
|
|
28
|
+
Archiver = "indexer-archiver",
|
|
29
|
+
Derivatives = "indexer-derivatives",
|
|
30
|
+
Explorer = "indexer-explorer",
|
|
31
|
+
InsuranceFund = "indexer-insurance-fund",
|
|
32
|
+
Meta = "indexer-meta",
|
|
33
|
+
Mito = "indexer-mito",
|
|
34
|
+
Dmm = "dmm",
|
|
35
|
+
OLP = "olp",
|
|
36
|
+
Referral = "referral",
|
|
37
|
+
Oracle = "indexer-oracle",
|
|
38
|
+
Portfolio = "indexer-portfolio",
|
|
39
|
+
Spot = "indexer-spot",
|
|
40
|
+
Transaction = "indexer-transaction",
|
|
41
|
+
Trading = "indexer-trading",
|
|
42
|
+
ChronosDerivative = "indexer-chronos-derivative",
|
|
43
|
+
ChronosSpot = "indexer-chronos-spot",
|
|
44
|
+
ChronosMarkets = "indexer-chronos-markets",
|
|
45
|
+
Campaign = "indexer-campaign",
|
|
46
|
+
Web3Gw = "web3-gateway",
|
|
47
|
+
Abacus = "abacus"
|
|
48
|
+
}
|
|
49
|
+
export declare enum WalletErrorActionModule {
|
|
50
|
+
SignTransaction = "sign-transaction",
|
|
51
|
+
SignEthereumTransaction = "sign-ethereum-transaction",
|
|
52
|
+
SendTransaction = "send-transaction",
|
|
53
|
+
SendEthereumTransaction = "send-ethereum-transaction",
|
|
54
|
+
SignArbitrary = "sign-arbitrary",
|
|
55
|
+
GetAccounts = "get-accounts",
|
|
56
|
+
GetNetworkId = "get-network-id",
|
|
57
|
+
GetChainId = "get-chain-id",
|
|
58
|
+
GetEthereumTransactionReceipt = "get-ethereum-transaction-receipt"
|
|
59
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export var ContractErrorModule;
|
|
2
|
+
(function (ContractErrorModule) {
|
|
3
|
+
ContractErrorModule["Erc20Contract"] = "erc20-contract";
|
|
4
|
+
ContractErrorModule["Peggy"] = "peggy-contract";
|
|
5
|
+
ContractErrorModule["PeggyOld"] = "peggy-old-contract";
|
|
6
|
+
})(ContractErrorModule || (ContractErrorModule = {}));
|
|
7
|
+
export var ChainErrorModule;
|
|
8
|
+
(function (ChainErrorModule) {
|
|
9
|
+
ChainErrorModule["Auction"] = "chain-auction";
|
|
10
|
+
ChainErrorModule["Auth"] = "chain-auth";
|
|
11
|
+
ChainErrorModule["Authz"] = "chain-authz";
|
|
12
|
+
ChainErrorModule["Bank"] = "chain-bank";
|
|
13
|
+
ChainErrorModule["Distribution"] = "chain-distribution";
|
|
14
|
+
ChainErrorModule["Exchange"] = "chain-exchange";
|
|
15
|
+
ChainErrorModule["Gov"] = "chain-gov";
|
|
16
|
+
ChainErrorModule["Ibc"] = "chain-ibc";
|
|
17
|
+
ChainErrorModule["InsuranceFund"] = "chain-insurance";
|
|
18
|
+
ChainErrorModule["Mint"] = "chain-mint";
|
|
19
|
+
ChainErrorModule["Oracle"] = "chain-oracle";
|
|
20
|
+
ChainErrorModule["Peggy"] = "chain-peggy";
|
|
21
|
+
ChainErrorModule["Staking"] = "chain-staking";
|
|
22
|
+
ChainErrorModule["Wasm"] = "chain-wasm";
|
|
23
|
+
ChainErrorModule["WasmX"] = "chain-wasmx";
|
|
24
|
+
ChainErrorModule["Tendermint"] = "chain-tendermint";
|
|
25
|
+
ChainErrorModule["Permissions"] = "chain-permissions";
|
|
26
|
+
})(ChainErrorModule || (ChainErrorModule = {}));
|
|
27
|
+
export var IndexerErrorModule;
|
|
28
|
+
(function (IndexerErrorModule) {
|
|
29
|
+
IndexerErrorModule["Account"] = "indexer-account";
|
|
30
|
+
IndexerErrorModule["Auction"] = "indexer-auction";
|
|
31
|
+
IndexerErrorModule["Archiver"] = "indexer-archiver";
|
|
32
|
+
IndexerErrorModule["Derivatives"] = "indexer-derivatives";
|
|
33
|
+
IndexerErrorModule["Explorer"] = "indexer-explorer";
|
|
34
|
+
IndexerErrorModule["InsuranceFund"] = "indexer-insurance-fund";
|
|
35
|
+
IndexerErrorModule["Meta"] = "indexer-meta";
|
|
36
|
+
IndexerErrorModule["Mito"] = "indexer-mito";
|
|
37
|
+
IndexerErrorModule["Dmm"] = "dmm";
|
|
38
|
+
IndexerErrorModule["OLP"] = "olp";
|
|
39
|
+
IndexerErrorModule["Referral"] = "referral";
|
|
40
|
+
IndexerErrorModule["Oracle"] = "indexer-oracle";
|
|
41
|
+
IndexerErrorModule["Portfolio"] = "indexer-portfolio";
|
|
42
|
+
IndexerErrorModule["Spot"] = "indexer-spot";
|
|
43
|
+
IndexerErrorModule["Transaction"] = "indexer-transaction";
|
|
44
|
+
IndexerErrorModule["Trading"] = "indexer-trading";
|
|
45
|
+
IndexerErrorModule["ChronosDerivative"] = "indexer-chronos-derivative";
|
|
46
|
+
IndexerErrorModule["ChronosSpot"] = "indexer-chronos-spot";
|
|
47
|
+
IndexerErrorModule["ChronosMarkets"] = "indexer-chronos-markets";
|
|
48
|
+
IndexerErrorModule["Campaign"] = "indexer-campaign";
|
|
49
|
+
IndexerErrorModule["Web3Gw"] = "web3-gateway";
|
|
50
|
+
IndexerErrorModule["Abacus"] = "abacus";
|
|
51
|
+
})(IndexerErrorModule || (IndexerErrorModule = {}));
|
|
52
|
+
export var WalletErrorActionModule;
|
|
53
|
+
(function (WalletErrorActionModule) {
|
|
54
|
+
WalletErrorActionModule["SignTransaction"] = "sign-transaction";
|
|
55
|
+
WalletErrorActionModule["SignEthereumTransaction"] = "sign-ethereum-transaction";
|
|
56
|
+
WalletErrorActionModule["SendTransaction"] = "send-transaction";
|
|
57
|
+
WalletErrorActionModule["SendEthereumTransaction"] = "send-ethereum-transaction";
|
|
58
|
+
WalletErrorActionModule["SignArbitrary"] = "sign-arbitrary";
|
|
59
|
+
WalletErrorActionModule["GetAccounts"] = "get-accounts";
|
|
60
|
+
WalletErrorActionModule["GetNetworkId"] = "get-network-id";
|
|
61
|
+
WalletErrorActionModule["GetChainId"] = "get-chain-id";
|
|
62
|
+
WalletErrorActionModule["GetEthereumTransactionReceipt"] = "get-ethereum-transaction-receipt";
|
|
63
|
+
})(WalletErrorActionModule || (WalletErrorActionModule = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isCommonLockedError: (error: string) => boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const isCommonLockedError = (error) => {
|
|
2
|
+
const commonMessages = [
|
|
3
|
+
'Ledger device: Incorrect length',
|
|
4
|
+
'Ledger device: INS_NOT_SUPPORTED',
|
|
5
|
+
'Ledger device: CLA_NOT_SUPPORTED',
|
|
6
|
+
'Unknown',
|
|
7
|
+
'Ledger device',
|
|
8
|
+
'CLA_NOT_SUPPORTED',
|
|
9
|
+
'CLA',
|
|
10
|
+
'Locked',
|
|
11
|
+
'Failed to open the device',
|
|
12
|
+
'Failed to open the device',
|
|
13
|
+
'Ledger Device is busy',
|
|
14
|
+
'Ledger device',
|
|
15
|
+
'UNKNOWN_ERROR',
|
|
16
|
+
];
|
|
17
|
+
return (commonMessages.some((m) => m.includes(error)) ||
|
|
18
|
+
commonMessages.some((m) => error.toLowerCase().includes(m)) ||
|
|
19
|
+
commonMessages.some((m) => m.toLowerCase().includes(error.toLowerCase())));
|
|
20
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ErrorContext, ErrorContextCode, TransactionChainErrorModule } from '../types/index.js';
|
|
2
|
+
export declare const parseErrorMessage: (message: string) => string;
|
|
3
|
+
export declare const mapFailedTransactionMessageFromString: (message: string) => {
|
|
4
|
+
message: string;
|
|
5
|
+
code: ErrorContextCode;
|
|
6
|
+
module?: TransactionChainErrorModule;
|
|
7
|
+
};
|
|
8
|
+
export declare const mapFailedTransactionMessage: (message: string, context?: ErrorContext) => {
|
|
9
|
+
message: string;
|
|
10
|
+
code: ErrorContextCode;
|
|
11
|
+
contextModule?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const mapMetamaskMessage: (message: string) => string;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { chainErrorMessagesMap, chainModuleCodeErrorMessagesMap, } from '../messages.js';
|
|
2
|
+
import { UnspecifiedErrorCode, } from '../types/index.js';
|
|
3
|
+
export const parseErrorMessage = (message) => {
|
|
4
|
+
const firstParse = message.split('message index: 0:');
|
|
5
|
+
if (firstParse.length === 1) {
|
|
6
|
+
const [firstParseString] = firstParse;
|
|
7
|
+
const secondParse = firstParseString.split(': invalid request');
|
|
8
|
+
const [secondParseString] = secondParse;
|
|
9
|
+
return secondParseString.trim().trimEnd();
|
|
10
|
+
}
|
|
11
|
+
const [, firstParseString] = firstParse;
|
|
12
|
+
const [actualMessage] = firstParseString.split(': invalid request');
|
|
13
|
+
return actualMessage.trim().trimEnd();
|
|
14
|
+
};
|
|
15
|
+
export const mapFailedTransactionMessageFromString = (message) => {
|
|
16
|
+
const parsedMessage = parseErrorMessage(message);
|
|
17
|
+
const messageInMapKey = Object.keys(chainErrorMessagesMap).find((key) => parsedMessage.toLowerCase().includes(key.toLowerCase()));
|
|
18
|
+
if (!messageInMapKey) {
|
|
19
|
+
return {
|
|
20
|
+
message: parsedMessage,
|
|
21
|
+
code: UnspecifiedErrorCode,
|
|
22
|
+
module: undefined,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return chainErrorMessagesMap[messageInMapKey];
|
|
26
|
+
};
|
|
27
|
+
export const mapFailedTransactionMessage = (message, context) => {
|
|
28
|
+
const getWasmErrorFromMessage = (message) => {
|
|
29
|
+
if (!message.includes('execute wasm contract failed')) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const ReasonPattern = /(.*?)execute wasm contract failed(.*?)/g;
|
|
33
|
+
const reason = ReasonPattern.exec(message);
|
|
34
|
+
if (!reason) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (reason.length < 2) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
return reason[1].replace('failed to execute message; message index: 0: ', '');
|
|
41
|
+
};
|
|
42
|
+
const getABCICode = (message) => {
|
|
43
|
+
const ABCICodePattern = /{key:"ABCICode"[ \t]+value:"(.*?)"}/g;
|
|
44
|
+
const ABCICode = ABCICodePattern.exec(message);
|
|
45
|
+
if (!ABCICode || ABCICode.length < 2) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
return Number(ABCICode[1]);
|
|
49
|
+
};
|
|
50
|
+
const getContextModule = (message) => {
|
|
51
|
+
const codespacePattern = /{key:"Codespace"[ \t]+value:"(.*?)"}/g;
|
|
52
|
+
const codespace = codespacePattern.exec(message);
|
|
53
|
+
if (!codespace || codespace.length < 2) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
return codespace[1];
|
|
57
|
+
};
|
|
58
|
+
const getReason = (message) => {
|
|
59
|
+
const ReasonPattern = /\[reason:"(.*?)"/g;
|
|
60
|
+
const codespace = ReasonPattern.exec(message);
|
|
61
|
+
if (!codespace || codespace.length < 2) {
|
|
62
|
+
if (message.includes('execute wasm contract failed')) {
|
|
63
|
+
return getWasmErrorFromMessage(message);
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const reason = codespace[1];
|
|
68
|
+
if (reason === 'execute wasm contract failed') {
|
|
69
|
+
const SubReasonPattern = /(.*?)Generic error:(.*?): execute wasm/g;
|
|
70
|
+
const subReason = SubReasonPattern.exec(message);
|
|
71
|
+
if (!subReason) {
|
|
72
|
+
return reason;
|
|
73
|
+
}
|
|
74
|
+
return subReason[2] || reason;
|
|
75
|
+
}
|
|
76
|
+
return reason;
|
|
77
|
+
};
|
|
78
|
+
const ABCICode = context && context.code ? context.code : getABCICode(message);
|
|
79
|
+
const contextModule = context?.contextModule || getContextModule(message);
|
|
80
|
+
const reason = getReason(message);
|
|
81
|
+
if (!ABCICode || !contextModule) {
|
|
82
|
+
const failedTxMap = mapFailedTransactionMessageFromString(message);
|
|
83
|
+
return {
|
|
84
|
+
...failedTxMap,
|
|
85
|
+
contextModule: failedTxMap.module || contextModule,
|
|
86
|
+
message: reason || failedTxMap.message,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const codespaceErrorMessages = chainModuleCodeErrorMessagesMap[contextModule];
|
|
90
|
+
if (!codespaceErrorMessages) {
|
|
91
|
+
return {
|
|
92
|
+
message: reason || message,
|
|
93
|
+
code: ABCICode,
|
|
94
|
+
contextModule,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
message: codespaceErrorMessages[ABCICode] || reason || message,
|
|
99
|
+
code: ABCICode,
|
|
100
|
+
contextModule,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
export const mapMetamaskMessage = (message) => {
|
|
104
|
+
const parsedMessage = message.trim().toLowerCase();
|
|
105
|
+
if (parsedMessage.includes('User denied message signature'.toLowerCase())) {
|
|
106
|
+
return 'The request has been rejected';
|
|
107
|
+
}
|
|
108
|
+
if (parsedMessage.toLowerCase().includes('user denied'.toLowerCase())) {
|
|
109
|
+
return 'The request has been rejected';
|
|
110
|
+
}
|
|
111
|
+
if (parsedMessage.toLowerCase().includes('provided chain'.toLowerCase())) {
|
|
112
|
+
return 'Your Metamask selected network is incorrect';
|
|
113
|
+
}
|
|
114
|
+
if (parsedMessage
|
|
115
|
+
.toLowerCase()
|
|
116
|
+
.includes('missing or invalid parameters'.toLowerCase())) {
|
|
117
|
+
return 'Please make sure you are using Metamask';
|
|
118
|
+
}
|
|
119
|
+
if (parsedMessage
|
|
120
|
+
.toLowerCase()
|
|
121
|
+
.includes('Keyring Controller signTypedMessage'.toLowerCase())) {
|
|
122
|
+
return 'Please ensure your Ledger is connected, unlocked and your Ethereum app is open.';
|
|
123
|
+
}
|
|
124
|
+
return message.replaceAll('Keyring Controller signTypedMessage:', '');
|
|
125
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Web3Exception, WalletException, TrezorException, BitGetException, LedgerException, GeneralException, MetamaskException, OkxWalletException, HttpRequestException, LedgerCosmosException, TrustWalletException, CosmosWalletException, TransactionException, GrpcUnaryRequestException } from './exceptions/exceptions/index.js';
|
|
2
|
+
export type ThrownException = GrpcUnaryRequestException | HttpRequestException | Web3Exception | GeneralException | LedgerException | MetamaskException | TrustWalletException | OkxWalletException | TrezorException | CosmosWalletException | TransactionException | WalletException | LedgerCosmosException | BitGetException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Exception } from './exceptions/types/index.js';
|
|
2
|
+
import { ThrownException } from './types.js';
|
|
3
|
+
export declare const THROWN_EXCEPTIONS: string[];
|
|
4
|
+
export declare const isThrownException: (exception: Error | Exception | ThrownException) => boolean;
|
|
5
|
+
export declare const formatNotificationDescription: (description: string) => {
|
|
6
|
+
description: string;
|
|
7
|
+
tooltip: string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const THROWN_EXCEPTIONS = [
|
|
2
|
+
'GrpcUnaryRequestException',
|
|
3
|
+
'HttpRequestException',
|
|
4
|
+
'Web3Exception',
|
|
5
|
+
'GeneralException',
|
|
6
|
+
'LedgerException',
|
|
7
|
+
'LedgerCosmosException',
|
|
8
|
+
'MetamaskException',
|
|
9
|
+
'TrezorException',
|
|
10
|
+
'CosmosWalletException',
|
|
11
|
+
'TransactionException',
|
|
12
|
+
'WalletException',
|
|
13
|
+
'TrustWalletException',
|
|
14
|
+
'OkxWalletException',
|
|
15
|
+
'BitGetException',
|
|
16
|
+
];
|
|
17
|
+
export const isThrownException = (exception) => {
|
|
18
|
+
if (THROWN_EXCEPTIONS.includes(exception.constructor.name)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (THROWN_EXCEPTIONS.includes(exception.name)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if ('errorClass' in exception &&
|
|
25
|
+
THROWN_EXCEPTIONS.includes(exception.errorClass)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
};
|
|
30
|
+
export const formatNotificationDescription = (description) => {
|
|
31
|
+
const DESCRIPTION_CHARACTER_LIMIT = 50;
|
|
32
|
+
if (description.length <= DESCRIPTION_CHARACTER_LIMIT) {
|
|
33
|
+
return {
|
|
34
|
+
description,
|
|
35
|
+
tooltip: '',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
description: description.slice(0, DESCRIPTION_CHARACTER_LIMIT) + ' ...',
|
|
40
|
+
tooltip: description,
|
|
41
|
+
};
|
|
42
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/exceptions",
|
|
3
3
|
"description": "List of exceptions that can be reused throughout Injective's projects.",
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.2",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"type": "module",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"shx": "^0.3.4"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "adf15fdda3172783b16fddba631c8054160fe772"
|
|
65
65
|
}
|