Skip to content

Commit

Permalink
fix: [IOCOM-1926] Do not show an error when closing the InApp Browser…
Browse files Browse the repository at this point in the history
…, 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
  • Loading branch information
Vangaorth authored Nov 14, 2024
1 parent c1cda52 commit 62db5f6
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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}`;
Expand All @@ -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";

0 comments on commit 62db5f6

Please sign in to comment.