File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ describe("error utils", () => {
25
25
normalizeEngineErrorMessage (
26
26
`eth_sendUserOperation error: {"message":"Invalid UserOperation signature or paymaster signature","code":-32507} Status: 200 Code: UNKNOWN` ,
27
27
) ,
28
- ) . toBe ( "Invalid UserOperation signature or paymaster signature " ) ;
28
+ ) . toBe ( "No active session found. Please sign in again. " ) ;
29
29
expect (
30
30
normalizeEngineErrorMessage (
31
31
"Simulation failed: TransactionError: Error - ERC20: transfer amount exceeds balance" ,
Original file line number Diff line number Diff line change @@ -51,12 +51,20 @@ export class TdkError extends Error {
51
51
}
52
52
}
53
53
54
- export const normalizeEngineErrorMessage = ( message : string ) => {
54
+ const ENGINE_ERROR_MESSAGE_MAP = {
55
+ "Invalid UserOperation signature or paymaster signature" :
56
+ "No active session found. Please sign in again." ,
57
+ } as const ;
58
+
59
+ export const normalizeEngineErrorMessage = ( rawMessage : string ) => {
55
60
const groups =
56
61
/ (?: r e a s o n : ' ( .* ?) ' a t ) | (?: r e a s o n = " e x e c u t i o n r e v e r t e d : ( .* ?) " ) | (?: e t h _ s e n d U s e r O p e r a t i o n e r r o r : { " m e s s a g e " : " ( .* ?) " | (?: S i m u l a t i o n f a i l e d : T r a n s a c t i o n E r r o r : E r r o r - ( .* ) ) | (?: ^ S i m u l a t i o n f a i l e d : ( .* ) ) | (?: ^ E r r o r - ( .* ) ) ) / gi. exec (
57
- message ,
62
+ rawMessage ,
58
63
) ;
59
- return groups ?. slice ( 1 ) . find ( ( group ) => group ) ?? message ;
64
+ const message = groups ?. slice ( 1 ) . find ( ( group ) => group ) ?? rawMessage ;
65
+ return message in ENGINE_ERROR_MESSAGE_MAP
66
+ ? ENGINE_ERROR_MESSAGE_MAP [ message as keyof typeof ENGINE_ERROR_MESSAGE_MAP ]
67
+ : message ;
60
68
} ;
61
69
62
70
export const parseEngineErrorMessage = ( err : unknown ) => {
You can’t perform that action at this time.
0 commit comments