Skip to content

Commit

Permalink
Fix error messages when reverting transactions (#1449)
Browse files Browse the repository at this point in the history
  • Loading branch information
flopez7 authored Jan 15, 2024
1 parent fa803de commit 60fa171
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions packages/sdk/typescript/human-protocol-sdk/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
*
Expand All @@ -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')) {
Expand Down

0 comments on commit 60fa171

Please sign in to comment.