Skip to content

Commit

Permalink
improve(suggested-fees): Filter underlying simulation reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl committed Oct 26, 2023
1 parent 1672213 commit efb4217
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,9 @@ export const getRelayerFeeDetails = async (
relayerAddress,
tokenPrice
);
} catch (_e: unknown) {
// Resolve and transform the error
const e = _e as Error;
// We want to mask this error as an Input error.
throw new InputError(e?.message);
} catch (err: unknown) {
const reason = resolveEthersError(err);
throw new InputError(`Failed to estimate relayer fees (${reason})`);
}
};

Expand Down Expand Up @@ -729,6 +727,14 @@ export function applyMapFilter<InputType, MapType>(
}, []);
}

export function resolveEthersError(err: unknown): string {
return sdk.typeguards.isEthersError(err)
? `${err.reason}: ${err.code}`
: sdk.typeguards.isError(err)
? err.message
: "unknown error";
}

/**
* Handles the recurring case of error handling
* @param endpoint A string numeric to indicate to the logging utility where this error occurs
Expand Down

0 comments on commit efb4217

Please sign in to comment.