From febf2000bdbd6dee612ce9db01b46ff58f08512f Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Mon, 10 Feb 2025 12:18:54 -0600 Subject: [PATCH] Retry signIn once to mitigate ephemeral fetch errors --- .../signUpModal/signUpModal.component.js | 9 +++++-- .../signUpModal/signUpModal.component.spec.js | 25 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/common/components/signUpModal/signUpModal.component.js b/src/common/components/signUpModal/signUpModal.component.js index 2270c472e..3ce31bda9 100644 --- a/src/common/components/signUpModal/signUpModal.component.js +++ b/src/common/components/signUpModal/signUpModal.component.js @@ -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) => { @@ -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) }) } diff --git a/src/common/components/signUpModal/signUpModal.component.spec.js b/src/common/components/signUpModal/signUpModal.component.spec.js index 98259d9db..10b4e29ad 100644 --- a/src/common/components/signUpModal/signUpModal.component.spec.js +++ b/src/common/components/signUpModal/signUpModal.component.spec.js @@ -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: { @@ -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 = {