From 62db5f605a341e99489d1dda10e5705e6b5ad5f2 Mon Sep 17 00:00:00 2001 From: Andrea Date: Thu, 14 Nov 2024 16:09:47 +0100 Subject: [PATCH] fix: [IOCOM-1926] Do not show an error when closing the InApp Browser, for FIMS flow (#6402) ## Short description This PR fixes the error toast being shown after closing the InApp Browser (FIMS authentication flow). ## List of changes proposed in this pull request - When the InApp Browsers is closed, the related login-utils library promise returns an error. We check for that specific error signature and, if it is so, we do not show any error Toast ## How to test Using the io-dev-api-server, check that no Error toast is shown when the InApp Browser is closed --- .../handleFimsGetRedirectUrlAndOpenIAB.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ts/features/fims/singleSignOn/saga/handleFimsGetRedirectUrlAndOpenIAB.ts b/ts/features/fims/singleSignOn/saga/handleFimsGetRedirectUrlAndOpenIAB.ts index 6fd04795f1c..75357b7d972 100644 --- a/ts/features/fims/singleSignOn/saga/handleFimsGetRedirectUrlAndOpenIAB.ts +++ b/ts/features/fims/singleSignOn/saga/handleFimsGetRedirectUrlAndOpenIAB.ts @@ -151,11 +151,7 @@ export function* handleFimsGetRedirectUrlAndOpenIAB( try { yield* call(openAuthenticationSession, inAppBrowserRedirectUrl, "", true); } catch (error: unknown) { - const debugMessage = `IAB opening failed: ${inAppBrowserErrorToHumanReadable( - error - )}`; - yield* call(computeAndTrackAuthenticationError, debugMessage); - yield* call(IOToast.error, I18n.t("FIMS.consentsScreen.inAppBrowserError")); + yield* call(handleInAppBrowserErrorIfNeeded, error); } } @@ -495,6 +491,16 @@ function* computeAndTrackInAppBrowserOpening( ); } +function* handleInAppBrowserErrorIfNeeded(error: unknown) { + if (!isInAppBrowserClosedError(error)) { + const debugMessage = `IAB opening failed: ${inAppBrowserErrorToHumanReadable( + error + )}`; + yield* call(computeAndTrackAuthenticationError, debugMessage); + yield* call(IOToast.error, I18n.t("FIMS.consentsScreen.inAppBrowserError")); + } +} + const inAppBrowserErrorToHumanReadable = (error: unknown) => { if (isLoginUtilsError(error)) { return `${error.code} ${error.userInfo?.error}`; @@ -504,3 +510,7 @@ const inAppBrowserErrorToHumanReadable = (error: unknown) => { const isLoginUtilsError = (error: unknown): error is LoginUtilsError => (error as LoginUtilsError).userInfo !== undefined; + +const isInAppBrowserClosedError = (error: unknown) => + isLoginUtilsError(error) && + error.userInfo?.error === "NativeAuthSessionClosed";