Skip to content

Commit

Permalink
fix: parse AA errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeday committed Dec 12, 2024
1 parent 75f1a0f commit 4ad4035
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions utils/getErrorMessage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SendCallsError } from 'modules/web3';

export enum ErrorMessage {
NOT_ENOUGH_ETHER = 'Not enough ether for gas.',
DENIED_SIG = 'User denied the transaction signature.',
Expand All @@ -17,6 +19,11 @@ export const getErrorMessage = (error: unknown): ErrorMessage => {
console.error('TX_ERROR:', e);
}

// Try to extract humane error from trusted error types
const parsedMessage = extractHumaneMessage(error);

if (parsedMessage) return parsedMessage;

const code = extractCodeFromError(error);
switch (code) {
case -32000: {
Expand Down Expand Up @@ -51,6 +58,14 @@ export const getErrorMessage = (error: unknown): ErrorMessage => {
}
};

// extracts message from Errors made by us
const extractHumaneMessage = (error: unknown) => {
if (error instanceof SendCallsError) {
error.message;
}
return null;
};

// type safe error code extractor
export const extractCodeFromError = (
error: unknown,
Expand Down

0 comments on commit 4ad4035

Please sign in to comment.