Skip to content

Commit

Permalink
Fixed error message returns null
Browse files Browse the repository at this point in the history
  • Loading branch information
moazzamgodil committed Aug 21, 2024
1 parent 1df73cc commit cc6a458
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/web3-errors-extract.min.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions lib/commonjs/lib/getErrorMessage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/commonjs/lib/getErrorMessage.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions lib/esm/lib/getErrorMessage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/esm/lib/getErrorMessage.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/types/lib/getErrorMessage.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-errors-extract",
"version": "0.2.0",
"version": "0.2.1",
"description": "Get EVM based web3 transaction revert messages or any other errors",
"main": "./lib/commonjs/index.js",
"module": "./lib/esm/index.js",
Expand Down
11 changes: 7 additions & 4 deletions src/lib/getErrorMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import getErrFromWeb3 from "./getweb3";

const _getErrorMessage = async (err: any, web3: Web3<RegisteredSubscription>, state: any): Promise<string> => {
const defaultErrMsg = "Something went wrong. Please try again later.";
let ret;
let ret: string | null = null;
if (err?.message && err.message?.includes("Internal JSON-RPC error.")) {
ret = await internalRPCError(err, web3);
} else if (
(err?.message &&
err.message?.includes("execution reverted:") &&
err.message?.indexOf("{") !== -1) || err?.data != null && err?.data != undefined
err.message?.includes("execution reverted:") &&
err.message?.indexOf("{") !== -1) || err?.data != null && err?.data != undefined
) {
ret = await executionReverted(err, state, web3);
} else if (err?.message && err.message?.includes("execution reverted:")) {
Expand All @@ -23,15 +23,18 @@ const _getErrorMessage = async (err: any, web3: Web3<RegisteredSubscription>, st
}

if (!ret) {
const errFromWeb3 = getErrFromWeb3(err, web3);
const errFromWeb3 = await getErrFromWeb3(err, web3);
if (errFromWeb3) {
ret = errFromWeb3;
}
}

if (ret) {
return ret;
} else if (err.message) {
return err.message;
}

return defaultErrMsg;
}

Expand Down

0 comments on commit cc6a458

Please sign in to comment.