Skip to content

Commit 611df50

Browse files
fix(ramps): show localized error for non-Error callback rejections
Bugbot flagged that wrapping non-Error rejections via `new Error(String(fetchError))` makes `normalizedError.message` truthy for almost any value (e.g., "undefined", "[object Object]", "null"), so the localized fallback was nearly unreachable and users could see those raw strings as the error. Mirror the `handleOnRefresh` guard (`fetchError instanceof Error && fetchError.message`) for the user-facing message while keeping the normalized Error for `Logger.error`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0a9a2cc commit 611df50

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

app/components/UI/Ramp/Views/OrderDetails/OrderDetails.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,35 @@ describe('OrderDetails', () => {
391391
});
392392
});
393393

394+
it.each([
395+
['undefined', undefined],
396+
['plain object', { foo: 'bar' }],
397+
['string', 'oops'],
398+
['null', null],
399+
])(
400+
'shows localized error when callback fetch rejects with non-Error value (%s)',
401+
async (_label, rejectedValue) => {
402+
mockUseParams.mockReturnValue({
403+
callbackUrl: 'https://callback.example?x=1',
404+
providerCode: 'moonpay',
405+
walletAddress: '0x123',
406+
});
407+
mockGetOrderById.mockReturnValue(undefined);
408+
mockGetOrderFromCallback.mockRejectedValue(rejectedValue);
409+
410+
const { getByText, queryByText } = render();
411+
412+
await waitFor(() => {
413+
expect(
414+
getByText('ramps_order_details.error_message'),
415+
).toBeOnTheScreen();
416+
});
417+
expect(queryByText('undefined')).toBeNull();
418+
expect(queryByText('[object Object]')).toBeNull();
419+
expect(queryByText('null')).toBeNull();
420+
},
421+
);
422+
394423
it('shows error state with retry when initial callback fetch fails', async () => {
395424
mockUseParams.mockReturnValue({
396425
callbackUrl: 'metamask://on-ramp/providers/paypal?orderId=abc',

app/components/UI/Ramp/Views/OrderDetails/OrderDetails.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ const OrderDetails = () => {
148148
callbackUrl,
149149
});
150150
setError(
151-
normalizedError.message
152-
? normalizedError.message
151+
fetchError instanceof Error && fetchError.message
152+
? fetchError.message
153153
: strings('ramps_order_details.error_message'),
154154
);
155155
} finally {

0 commit comments

Comments
 (0)