Fix Issue with Retrying Failed Request After Successful Token Refresh #119
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
In the application, after successfully obtaining a Refresh Token, a new request is automatically sent with the refreshed token. However, if a different error (such as 500 Internal Server Error) is encountered during this second request, instead of an authentication error (
401 Unauthorized
), the original authentication error from the first request is mistakenly thrown again. This prevents handling different errors correctly after the Refresh Token process.Solution:
This PR ensures that if a different error occurs during the second request after a successful token refresh, that error is properly caught and handled. If a new error is encountered, the original authentication error is not thrown again, and the new error is raised.
Changes Made:
New Error Handling Added: If a new error occurs during the request after the Refresh Token process, it is handled with
handler.next(err)
, and the previous error is not reused.Request Cancellation and Callback: When an error occurs after the Refresh Token process, the request is canceled using
error.requestOptions.cancelToken?.cancel()
and theonRefreshFail
callback is triggered. This ensures the user is informed about the failure of the Refresh Token process.Code Example:
With This Change:
cancelToken
andonRefreshFail
callbacks function correctly during error management and request cancellation.Tested Scenarios:
onRefreshFail
function is successfully triggered.Fixes #118