From bf986b941a98602dabfca8fd6efb7b51acca3669 Mon Sep 17 00:00:00 2001 From: mehmetali <36207866+realmehmetali@users.noreply.github.com> Date: Sat, 18 Jul 2026 06:45:01 -0700 Subject: [PATCH] fix: propagate pending user operation RPC errors --- .../payment/getPaymentStatus.test.ts | 34 +++++++++++++++++++ .../src/interface/payment/getPaymentStatus.ts | 5 +++ 2 files changed, 39 insertions(+) diff --git a/packages/account-sdk/src/interface/payment/getPaymentStatus.test.ts b/packages/account-sdk/src/interface/payment/getPaymentStatus.test.ts index dae63bba..fda19322 100644 --- a/packages/account-sdk/src/interface/payment/getPaymentStatus.test.ts +++ b/packages/account-sdk/src/interface/payment/getPaymentStatus.test.ts @@ -168,6 +168,40 @@ describe('getPaymentStatus', () => { }); }); + it('should propagate RPC errors from the pending user operation lookup', async () => { + vi.mocked(fetch) + .mockResolvedValueOnce({ + json: async () => ({ jsonrpc: '2.0', id: 1, result: null }), + } as Response) + .mockResolvedValueOnce({ + json: async () => ({ + jsonrpc: '2.0', + id: 2, + error: { + code: -32602, + message: 'Invalid user operation hash', + }, + }), + } as Response); + + await expect( + getPaymentStatus({ + id: '0xinvalid', + testnet: false, + }) + ).rejects.toThrow('RPC error: Invalid user operation hash'); + + const { logPaymentStatusCheckCompleted, logPaymentStatusCheckError } = await import( + ':core/telemetry/events/payment.js' + ); + expect(logPaymentStatusCheckCompleted).not.toHaveBeenCalled(); + expect(logPaymentStatusCheckError).toHaveBeenCalledWith({ + testnet: false, + correlationId: 'mock-correlation-id', + errorMessage: 'RPC error: Invalid user operation hash', + }); + }); + it('should handle RPC errors gracefully', async () => { vi.mocked(fetch).mockResolvedValueOnce({ json: async () => ({ diff --git a/packages/account-sdk/src/interface/payment/getPaymentStatus.ts b/packages/account-sdk/src/interface/payment/getPaymentStatus.ts index c2bc100b..9e17f517 100644 --- a/packages/account-sdk/src/interface/payment/getPaymentStatus.ts +++ b/packages/account-sdk/src/interface/payment/getPaymentStatus.ts @@ -105,6 +105,11 @@ export async function getPaymentStatus(options: PaymentStatusOptions): Promise

res.json()); + if (userOpResponse.error) { + const errorMessage = userOpResponse.error.message || 'Network error'; + throw new Error(`RPC error: ${errorMessage}`); + } + if (userOpResponse.result) { // UserOp exists but no receipt yet - it's pending if (telemetry) {