Skip to content

Commit 34ca5ed

Browse files
runway-github[bot]georgeweilerwachunei
authored
chore(runway): cherry-pick fix(ramps): cp-7.58.0 do not throw when user details fetch is 401 (#21648)
- fix(ramps): cp-7.58.0 do not throw when user details fetch is 401 (#21633) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR fixes a bug where an error would display for users who's token has expired. Now they are silently logged out instead of throwing an error that is displayed to the user. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: fixed bug where an error message was incorrectly displayed to the user on the deposit page ## **Related issues** Fixes: #21642 ## **Manual testing steps** ```gherkin Feature: User Error Fix Scenario: logged-out user should not see error message Given user token has expired When user visits the deposit page Then user should not see an error ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <img width="509" height="897" alt="Screenshot 2025-10-24 at 11 58 22 AM" src="https://github.com/user-attachments/assets/7e771356-f54e-4208-af21-8eb2004d017c" /> <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Stops rethrowing 401 errors in `useDepositUser` by logging out silently; updates tests to reflect non-throwing behavior on 401. > > - **Hook (`useDepositUser`)** > - On 401 from `fetchUserDetails`, log and call `logoutFromProvider(false)` without rethrowing. > - Only rethrow non-401 errors. > - **Tests (`useDepositUser.test.ts`)** > - Update 401 test to expect silent logout and no thrown error. > - Adjust setup to not provide stale data during 401 case. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit a08f393. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: Pedro Pablo Aste Kompen <[email protected]> [3f30cb5](3f30cb5) Co-authored-by: George Weiler <[email protected]> Co-authored-by: Pedro Pablo Aste Kompen <[email protected]>
1 parent a007d2e commit 34ca5ed

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

app/components/UI/Ramp/Deposit/hooks/useDepositUser.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ describe('useDepositUser', () => {
271271
expect(mockFetchUserDetails).toHaveBeenCalled();
272272
});
273273

274-
it('logs out and throws on 401 error', async () => {
274+
it('logs out but does not throw on 401 error', async () => {
275275
const error401 = Object.assign(new Error('Unauthorized'), {
276276
status: 401,
277277
}) as AxiosError;
@@ -284,13 +284,11 @@ describe('useDepositUser', () => {
284284
);
285285

286286
mockFetchUserDetails.mockRejectedValue(error401);
287-
setupMockSdkMethod({ data: mockUserDetails });
287+
setupMockSdkMethod();
288288

289289
const { result } = renderHook(() => useDepositUser());
290290

291-
await expect(result.current.fetchUserDetails()).rejects.toThrow(
292-
'Unauthorized',
293-
);
291+
await result.current.fetchUserDetails();
294292

295293
expect(mockLogoutFromProvider).toHaveBeenCalledWith(false);
296294
});

app/components/UI/Ramp/Deposit/hooks/useDepositUser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ export function useDepositUser() {
2222
if ((error as AxiosError).status === 401) {
2323
Logger.log('useDepositUser: 401 error, clearing authentication');
2424
await logoutFromProvider(false);
25+
} else {
26+
throw error;
2527
}
26-
throw error;
2728
}
2829
}, [fetchUserDetails, logoutFromProvider]);
2930

0 commit comments

Comments
 (0)