From 60fa171f068f18ea2563ee0dbb1ad3f96cf3ef5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20L=C3=B3pez?= <50665615+flopez7@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:52:28 +0100 Subject: [PATCH] Fix error messages when reverting transactions (#1449) --- .../typescript/human-protocol-sdk/src/utils.ts | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/packages/sdk/typescript/human-protocol-sdk/src/utils.ts b/packages/sdk/typescript/human-protocol-sdk/src/utils.ts index 7838390123..b1ade8a602 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/utils.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/utils.ts @@ -11,21 +11,6 @@ import { TransactionReplaced, } from './error'; -/** - * **Get specific error text.* - * - * @param {any} error - An error message. - * @returns - */ -export const getRevertReason = (error: any): string => { - const prefix = "reverted with reason string '"; - const suffix = "'"; - const message = error.data.substring( - error.data.indexOf(prefix) + prefix.length - ); - return message.substring(0, message.indexOf(suffix)); -}; - /** * **Handle and throw the error.* * @@ -36,8 +21,7 @@ export const throwError = (e: any) => { if (ethers.isError(e, 'INVALID_ARGUMENT')) { throw new InvalidArgumentError(e.message); } else if (ethers.isError(e, 'CALL_EXCEPTION')) { - const reason = getRevertReason(e.data); - throw new ContractExecutionError(reason); + throw new ContractExecutionError(e.reason as string); } else if (ethers.isError(e, 'TRANSACTION_REPLACED')) { throw new TransactionReplaced(e.message); } else if (ethers.isError(e, 'REPLACEMENT_UNDERPRICED')) {