Skip to content

Conversation

@NickPhura
Copy link
Contributor

@NickPhura NickPhura commented Aug 29, 2023

Links to Jira Tickets

n/a

Description of Changes

Add retry mechanic to useAxios to handle the case where your keycloak token has expired while working in the APP.

This can occur if you sit on an App page for longer than 5 minutes, without interacting with the api. In this case, the token will have quietly expired (5 minutes in Standard realm), and your next http request is guaranteed to fail.

Updated useAxios so that if the response fails, and the status is specifically a 401 or 403, then it attempts to refresh the token, and if it is successfully refreshed, re-run the last failed request.

Add useAxios tests.

Testing Notes

Let your token expire (wait 5 minutes), and then make some request (ie: save project, or similar), and you should see 2 requests get made, the first of which fails, and the second of which succeeds. The second call should also have a new/different bearer token in the headers.

… token has expired, but your refresh token is still valid.
@github-actions
Copy link

@NickPhura NickPhura changed the title TechDebt: Add retry mechanic to useAxios to handle the case where your keycloak… TechDebt: useAxios 401/403 Request Retry Aug 29, 2023
@codecov
Copy link

codecov bot commented Aug 29, 2023

Codecov Report

Merging #1079 (1f0bc99) into dev (105829d) will increase coverage by 0.03%.
The diff coverage is 83.33%.

@@            Coverage Diff             @@
##              dev    #1079      +/-   ##
==========================================
+ Coverage   64.31%   64.35%   +0.03%     
==========================================
  Files         440      440              
  Lines       13501    13512      +11     
  Branches     2147     2151       +4     
==========================================
+ Hits         8683     8695      +12     
+ Misses       4288     4287       -1     
  Partials      530      530              
Files Changed Coverage Δ
app/src/hooks/api/useAxios.ts 92.00% <83.33%> (+13.42%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@NickPhura NickPhura marked this pull request as ready for review August 29, 2023 17:30
@github-actions
Copy link

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@KjartanE KjartanE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked on local 🐈

@NickPhura NickPhura merged commit 5fe85d7 into dev Aug 30, 2023
@NickPhura NickPhura deleted the np_techdebt branch August 30, 2023 00:10
KjartanE pushed a commit that referenced this pull request Sep 5, 2023
* Add retry mechanic to useAxios to handle the case where your keycloak token has expired, but your refresh token is still valid.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants