Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: [IOPID-2406] Added handling of errorMessage during login #6361

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions locales/en/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ profile:
title: Preferences
description: Customize your app experience
security:
title: Security
title: Security and login
description: Manage biometric access and unlock code
privacy:
title: Privacy Policy and Terms of Service
Expand Down Expand Up @@ -504,7 +504,7 @@ profile:
nameSurname: Name and surname
fiscalCode: Fiscal code
security:
title: Security
title: Security and login
subtitle: Manage in-app authentication methods.
list:
biometric_recognition:
Expand Down
4 changes: 2 additions & 2 deletions locales/it/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ profile:
title: Preferenze
description: Gestisci le preferenze dell'applicazione
security:
title: Sicurezza
title: Sicurezza e accesso
description: Gestisci accesso biometrico e codice di sblocco
privacy:
title: Privacy e Condizioni d'uso
Expand Down Expand Up @@ -504,7 +504,7 @@ profile:
nameSurname: Nome e cognome
fiscalCode: Codice Fiscale
security:
title: Sicurezza
title: Sicurezza e accesso
subtitle: Gestisci le modalità di autenticazione in app.
list:
biometric_recognition:
Expand Down
8 changes: 5 additions & 3 deletions ts/features/cieLogin/components/CieIdLoginWebView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ const CieIdLoginWebView = ({ spidLevel, isUat }: CieIdLoginProps) => {
useLollipopLoginSource(navigateToCieIdAuthenticationError, loginUri);

const handleLoginFailure = useCallback(
(code?: string) => {
(code?: string, message?: string) => {
// TODO: Check missing SAML response (error message) https://pagopa.atlassian.net/browse/IOPID-2406
dispatch(
loginFailure({
error: new Error(`login failure with code ${code || "n/a"}`),
error: new Error(
`login failure with code ${code || message || "n/a"}`
),
idp: "cie"
})
);
Expand All @@ -90,7 +92,7 @@ const CieIdLoginWebView = ({ spidLevel, isUat }: CieIdLoginProps) => {
navigation.replace(ROUTES.AUTHENTICATION, {
screen: ROUTES.AUTH_ERROR_SCREEN,
params: {
errorCode: code,
errorCodeOrMessage: code || message,
authMethod: "CIE_ID",
authLevel: "L2",
params: { spidLevel, isUat }
Expand Down
6 changes: 3 additions & 3 deletions ts/screens/authentication/AuthErrorScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { UnlockAccessProps } from "./UnlockAccessComponent";
import AuthErrorComponent from "./components/AuthErrorComponent";

type CommonAuthErrorScreenProps = {
errorCode?: string;
errorCodeOrMessage?: string;
} & UnlockAccessProps;

type SpidProps = {
Expand Down Expand Up @@ -42,7 +42,7 @@ const authScreenByAuthMethod = {
const AuthErrorScreen = () => {
const route =
useRoute<Route<typeof ROUTES.AUTH_ERROR_SCREEN, AuthErrorScreenProps>>();
const { errorCode, authMethod, authLevel } = route.params;
const { errorCodeOrMessage, authMethod, authLevel } = route.params;

const navigation = useIONavigation();

Expand Down Expand Up @@ -78,7 +78,7 @@ const AuthErrorScreen = () => {
authLevel={authLevel}
onCancel={onCancel}
onRetry={onRetry}
errorCode={errorCode}
errorCodeOrMessage={errorCodeOrMessage}
/>
);
};
Expand Down
33 changes: 20 additions & 13 deletions ts/screens/authentication/IdpLoginScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ const IdpLoginScreen = () => {
const [requestState, setRequestState] = useState<pot.Pot<true, ErrorType>>(
pot.noneLoading
);
const [errorCode, setErrorCode] = useState<string | undefined>(undefined);
const [errorCodeOrMessage, setErrorCodeOrMessage] = useState<
string | undefined
>(undefined);
const [loginTrace, setLoginTrace] = useState<string | undefined>(undefined);

const handleOnLollipopCheckFailure = useCallback(() => {
Expand Down Expand Up @@ -140,28 +142,33 @@ const IdpLoginScreen = () => {
);

const handleLoginFailure = useCallback(
(code?: string) => {
(code?: string, message?: string) => {
dispatch(
loginFailure({
error: new Error(`login failure with code ${code || "n/a"}`),
error: new Error(
`login failure with code ${code || message || "n/a"}`
),
idp
})
);
const logText = pipe(
code,
O.fromNullable,
O.fromNullable(code || message),
O.fold(
() => "login failed with no error code available",
ec =>
`login failed with code (${ec}) : ${getSpidErrorCodeDescription(
ec
)}`
() => "login failed with no error code or message available",
_ => {
if (code) {
return `login failed with code (${code}) : ${getSpidErrorCodeDescription(
code
)}`;
}
return `login failed with message ${message}`;
}
)
);

handleSendAssistanceLog(choosenTool, logText);
setRequestState(pot.noneError(ErrorType.LOGIN_ERROR));
setErrorCode(code);
setErrorCodeOrMessage(code || message);
},
[dispatch, choosenTool, idp]
);
Expand Down Expand Up @@ -259,13 +266,13 @@ const IdpLoginScreen = () => {
navigate(ROUTES.AUTHENTICATION, {
screen: ROUTES.AUTH_ERROR_SCREEN,
params: {
errorCode,
errorCodeOrMessage,
authMethod: "SPID",
authLevel: "L2",
onRetry: onRetryButtonPressed
}
});
}, [errorCode, onRetryButtonPressed, navigate]);
}, [errorCodeOrMessage, onRetryButtonPressed, navigate]);

useEffect(() => {
if (pot.isError(requestState)) {
Expand Down
20 changes: 10 additions & 10 deletions ts/screens/authentication/__tests__/AuthErrorComponent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,63 @@ describe("AuthErrorComponent", () => {
const testCases = [
{
description: "renders correctly with generic error code",
errorCode: "generic",
errorCodeOrMessage: "generic",
expectedTitle: I18n.t("authentication.auth_errors.generic.title"),
expectedSubtitle: I18n.t("authentication.auth_errors.generic.subtitle"),
expectRetryCalled: true,
expectCancelCalled: true
},
{
description: 'renders correctly with error code "19"',
errorCode: "19",
errorCodeOrMessage: "19",
expectedTitle: I18n.t("authentication.auth_errors.error_19.title"),
expectedSubtitle: I18n.t("authentication.auth_errors.error_19.subtitle"),
expectRetryCalled: true,
expectCancelCalled: true
},
{
description: 'renders correctly with error code "20"',
errorCode: "20",
errorCodeOrMessage: "20",
expectedTitle: I18n.t("authentication.auth_errors.error_20.title"),
expectedSubtitle: I18n.t("authentication.auth_errors.error_20.subtitle"),
expectRetryCalled: true,
expectCancelCalled: true
},
{
description: 'renders correctly with error code "21"',
errorCode: "21",
errorCodeOrMessage: "21",
expectedTitle: I18n.t("authentication.auth_errors.error_21.title"),
expectedSubtitle: I18n.t("authentication.auth_errors.error_21.subtitle"),
expectRetryCalled: true,
expectCancelCalled: true
},
{
description: 'renders correctly with error code "22"',
errorCode: "22",
errorCodeOrMessage: "22",
expectedTitle: I18n.t("authentication.auth_errors.error_22.title"),
expectedSubtitle: I18n.t("authentication.auth_errors.error_22.subtitle"),
expectRetryCalled: true,
expectCancelCalled: true
},
{
description: 'renders correctly with error code "23"',
errorCode: "23",
errorCodeOrMessage: "23",
expectedTitle: I18n.t("authentication.auth_errors.error_23.title"),
expectedSubtitle: I18n.t("authentication.auth_errors.error_23.subtitle"),
expectRetryCalled: false,
expectCancelCalled: true
},
{
description: 'renders correctly with error code "25"',
errorCode: "25",
errorCodeOrMessage: "25",
expectedTitle: I18n.t("authentication.auth_errors.error_25.title"),
expectedSubtitle: I18n.t("authentication.auth_errors.error_25.subtitle"),
expectRetryCalled: true,
expectCancelCalled: true
},
{
description: 'renders correctly with error code "1001"',
errorCode: "1001",
errorCodeOrMessage: "1001",
expectedTitle: I18n.t("authentication.auth_errors.error_1001.title"),
expectedSubtitle: I18n.t(
"authentication.auth_errors.error_1001.subtitle"
Expand All @@ -76,7 +76,7 @@ describe("AuthErrorComponent", () => {
testCases.forEach(
({
description,
errorCode,
errorCodeOrMessage,
expectedTitle,
expectedSubtitle,
expectRetryCalled,
Expand All @@ -89,7 +89,7 @@ describe("AuthErrorComponent", () => {
const { getByText, queryByText } = render(
<AuthErrorComponent
authLevel="L2"
errorCode={errorCode}
errorCodeOrMessage={errorCodeOrMessage}
onRetry={onRetryMock}
onCancel={onCancelMock}
/>
Expand Down
22 changes: 14 additions & 8 deletions ts/screens/authentication/cie/CieConsentDataUsageScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const CieConsentDataUsageScreen = () => {
const dispatch = useIODispatch();
const [hasError, setHasError] = useState<boolean>(false);
const [isLoginSuccess, setIsLoginSuccess] = useState<boolean | undefined>();
const [errorCode, setErrorCode] = useState<string | undefined>();
const [errorCodeOrMessage, setErrorCodeOrMessage] = useState<
string | undefined
>();
const { showAlert } = useOnboardingAbortAlert();
const navigation = useIONavigation();
const loginSuccessDispatch = useCallback(
Expand Down Expand Up @@ -106,11 +108,11 @@ const CieConsentDataUsageScreen = () => {
);

const handleLoginFailure = useCallback(
(errorCode?: string) => {
(code?: string, message?: string) => {
setHasError(true);
setErrorCode(errorCode);
setErrorCodeOrMessage(code);
loginFailureDispatch(
new Error(`login CIE failure with code ${errorCode || "n/a"}`)
new Error(`login CIE failure with code ${code || message || "n/a"}`)
);
},
[loginFailureDispatch]
Expand All @@ -130,19 +132,23 @@ const CieConsentDataUsageScreen = () => {
);

useEffect(() => {
if (hasError && errorCode === "22") {
if (hasError && errorCodeOrMessage === "22") {
trackLoginCieDataSharingError();
}
}, [errorCode, hasError]);
}, [errorCodeOrMessage, hasError]);

useEffect(() => {
if (hasError) {
navigation.navigate(ROUTES.AUTHENTICATION, {
screen: ROUTES.AUTH_ERROR_SCREEN,
params: { errorCode, authMethod: "CIE", authLevel: "L2" }
params: {
errorCodeOrMessage,
authMethod: "CIE",
authLevel: "L2"
}
});
}
}, [errorCode, hasError, navigation]);
}, [errorCodeOrMessage, hasError, navigation]);

if (isLoginSuccess) {
return <LoaderComponent />;
Expand Down
Loading
Loading