Skip to content

Commit

Permalink
Merge pull request #1149 from CruGlobal/2362-okta-fetch-error
Browse files Browse the repository at this point in the history
[EP-2362] Retry signIn once to mitigate ephemeral fetch errors
  • Loading branch information
canac authored Feb 10, 2025
2 parents 377d6cd + febf200 commit 58da428
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/common/components/signUpModal/signUpModal.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class SignUpModalController {
// Render the widget again to show new step
// Unfortunately, this removes the error messages, which is why we inject them after rendering
this.oktaSignInWidget.remove()
this.oktaSignInWidget.renderEl(
return this.oktaSignInWidget.renderEl(
{ el: '#osw-container' },
null,
(error) => {
Expand All @@ -550,12 +550,17 @@ class SignUpModalController {
)
}

signIn () {
signIn (retrying = false) {
return this.oktaSignInWidget.showSignInAndRedirect({
el: '#osw-container'
}).then(tokens => {
this.oktaSignInWidget.authClient.handleLoginRedirect(tokens)
}).catch(error => {
if (!retrying) {
// Retry once
return this.reRenderWidget().then(() => this.signIn(true))
}

this.$log.error('Error showing Okta sign in widget.', error)
})
}
Expand Down
25 changes: 14 additions & 11 deletions src/common/components/signUpModal/signUpModal.component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1222,11 +1222,12 @@ describe('signUpForm', function () {
});
});

it('should handle an error with $log', (done) => {
const error = new Error('Error signing in');
jest.spyOn($ctrl.$log, 'error').mockImplementation(() => {});
const showSignInAndRedirect = jest.fn().mockRejectedValue(error);
const handleLoginRedirect = jest.fn();
it('should handle an error with $log and retry once', (done) => {
const error = new Error('Error signing in')
jest.spyOn($ctrl.$log, 'error').mockImplementation(() => {})
jest.spyOn($ctrl, 'reRenderWidget').mockResolvedValue()
const showSignInAndRedirect = jest.fn().mockRejectedValue(error)
const handleLoginRedirect = jest.fn()
$ctrl.oktaSignInWidget = {
showSignInAndRedirect,
authClient: {
Expand All @@ -1235,12 +1236,14 @@ describe('signUpForm', function () {
}

$ctrl.signIn().then(() => {
expect(handleLoginRedirect).not.toHaveBeenCalled()
expect($ctrl.$log.error).toHaveBeenCalledWith('Error showing Okta sign in widget.', error)
done()
});
});
});
expect(handleLoginRedirect).not.toHaveBeenCalled()
expect($ctrl.reRenderWidget).toHaveBeenCalledTimes(1)
expect($ctrl.$log.error).toHaveBeenCalledTimes(1)
expect($ctrl.$log.error).toHaveBeenCalledWith('Error showing Okta sign in widget.', error)
done()
})
})
})

describe('loadDonorDetails()', () => {
const signUpFormData = {
Expand Down

0 comments on commit 58da428

Please sign in to comment.