Skip to content

Commit 61be736

Browse files
authored
feat: support call reverted
1 parent a005397 commit 61be736

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Here is the complete list of returned objects:
7171
| `TRANSACTION_RAN_OUT_OF_GAS` | The transaction gas limit as a string. |
7272
| `TRANSACTION_UNDERPRICED` | `undefined` |
7373
| `REJECTED_TRANSACTION` | The reason why the transaction rejected. |
74+
| `CALL_REVERTED` | The reason why the call reverted. |
7475
| `EXECUTION_REVERTED` | The reason why the transaction reverted. |
7576
| `NONCE_TOO_LOW` | The transaction nonce as a string. |
7677
| `INSUFFICIENT_FUNDS_FOR_GAS` | `undefined` |

lib/__tests__/getParsedEthersError.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ describe("getParsedEthersError", () => {
8282
context: message,
8383
});
8484
});
85+
it("should handle calls reverted via code", () => {
86+
const reason = "TOKEN_ID_DOES_NOT_EXIST";
87+
88+
const result = getParsedEthersError({
89+
message: "",
90+
code: ETHERS_ERROR_CODES.CALL_EXCEPTION,
91+
reason,
92+
});
93+
94+
expect(result).toEqual({
95+
errorCode: RETURN_VALUE_ERROR_CODES.CALL_REVERTED,
96+
context: reason,
97+
});
98+
});
8599
it("should handle transaction rejected via code", () => {
86100
const message = "User rejected transaction";
87101

lib/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const RETURN_VALUE_ERROR_CODES = {
22
TRANSACTION_RAN_OUT_OF_GAS: "TRANSACTION_RAN_OUT_OF_GAS",
33
TRANSACTION_UNDERPRICED: "TRANSACTION_UNDERPRICED",
44
REJECTED_TRANSACTION: "REJECTED_TRANSACTION",
5+
CALL_REVERTED: "CALL_REVERTED",
56
EXECUTION_REVERTED: "EXECUTION_REVERTED",
67
NONCE_TOO_LOW: "NONCE_TOO_LOW",
78
INSUFFICIENT_FUNDS_FOR_GAS: "INSUFFICIENT_FUNDS_FOR_GAS",
@@ -16,6 +17,7 @@ export const ETHERS_ERROR_CODES = {
1617
NONCE_EXPIRED: "NONCE_EXPIRED",
1718
UNPREDICTABLE_GAS_LIMIT: "UNPREDICTABLE_GAS_LIMIT",
1819
ACTION_REJECTED: "ACTION_REJECTED",
20+
CALL_EXCEPTION: "CALL_EXCEPTION",
1921
};
2022

2123
export const NESTED_ETHERS_ERROR_CODES = {

lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface EthersError {
1717
gasUsed: BigNumber;
1818
};
1919
action?: string;
20+
reason?: string;
2021
}
2122

2223
export interface NestedEthersError {

lib/utils/getTopLevelKnownError.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ export function getTopLevelKnownError(
2626
};
2727
}
2828

29+
if (
30+
ethersError.code === ETHERS_ERROR_CODES.CALL_EXCEPTION &&
31+
ethersError.reason !== undefined
32+
) {
33+
return {
34+
errorCode: RETURN_VALUE_ERROR_CODES.CALL_REVERTED,
35+
context: ethersError.reason,
36+
};
37+
}
38+
2939
const unpredictableGasLimitError = getUnpredictableGasLimitError(ethersError);
3040
if (unpredictableGasLimitError !== undefined) {
3141
return unpredictableGasLimitError;

0 commit comments

Comments
 (0)