-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy patherror.ts
More file actions
46 lines (38 loc) · 1.44 KB
/
Copy patherror.ts
File metadata and controls
46 lines (38 loc) · 1.44 KB
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
import { ethers } from "ethers";
import { stringify } from "thirdweb/utils";
import { isEthersErrorCode } from "./ethers";
export const wrapError = (error: unknown, prefix: "RPC" | "Bundler") =>
new Error(`[${prefix}] ${prettifyError(error)}`);
export const prettifyError = (error: unknown): string =>
error instanceof Error ? error.message : stringify(error);
const _parseMessage = (error: unknown): string | null => {
return error && typeof error === "object" && "message" in error
? (error.message as string).toLowerCase()
: null;
};
export const isNonceAlreadyUsedError = (error: unknown) => {
const message = _parseMessage(error);
if (message) {
return (
message.includes("nonce too low") || message.includes("already known") || message.includes("incorrect account sequence")
);
}
return isEthersErrorCode(error, ethers.errors.NONCE_EXPIRED);
};
export const isReplacementGasFeeTooLow = (error: unknown) => {
const message = _parseMessage(error);
if (message) {
return (
message.includes("replacement fee too low") ||
message.includes("replacement transaction underpriced")
);
}
return isEthersErrorCode(error, ethers.errors.REPLACEMENT_UNDERPRICED);
};
export const isInsufficientFundsError = (error: unknown) => {
const message = _parseMessage(error);
if (message) {
return message.includes("insufficient funds");
}
return isEthersErrorCode(error, ethers.errors.INSUFFICIENT_FUNDS);
};