diff --git a/src/oneid/oneid-fe/src/hooks/useLoginError.test.tsx b/src/oneid/oneid-fe/src/hooks/useLoginError.test.tsx index 285758a1..fdc821e6 100644 --- a/src/oneid/oneid-fe/src/hooks/useLoginError.test.tsx +++ b/src/oneid/oneid-fe/src/hooks/useLoginError.test.tsx @@ -1,54 +1,56 @@ import { renderHook } from '@testing-library/react'; import { t } from 'i18next'; - -import { useLoginError } from './useLoginError'; +import { ERROR_CODE, ErrorData, useLoginError } from './useLoginError'; describe('useLoginError', () => { - const cases = [ + const cases: Array<{ + errorCode: ERROR_CODE; + expected: ErrorData; + }> = [ { - errorCode: '19', + errorCode: ERROR_CODE.TOO_MANY_ATTEMPTS, expected: { title: t('loginError.tooManyAttempts.title'), description: t('loginError.tooManyAttempts.description'), }, }, { - errorCode: '20', + errorCode: ERROR_CODE.INCOMPATIBLE_CREDENTIALS, expected: { title: t('loginError.incompatibleCredentials.title'), description: t('loginError.incompatibleCredentials.description'), }, }, { - errorCode: '21', + errorCode: ERROR_CODE.AUTH_TIMEOUT, expected: { title: t('loginError.authTimeout.title'), description: t('loginError.authTimeout.description'), }, }, { - errorCode: '22', + errorCode: ERROR_CODE.DENIED_BY_USER, expected: { title: t('loginError.deniedByUser.title'), description: t('loginError.deniedByUser.description'), }, }, { - errorCode: '23', + errorCode: ERROR_CODE.SUSPENDED_OR_REVOKED, expected: { title: t('loginError.suspendedOrRevoked.title'), description: t('loginError.suspendedOrRevoked.description'), }, }, { - errorCode: '25', + errorCode: ERROR_CODE.CANCELED_BY_USER, expected: { title: t('loginError.canceledbyUser.title'), description: t('loginError.canceledbyUser.description'), }, }, { - errorCode: 'unknown', + errorCode: ERROR_CODE.MISSING_IDP, expected: { title: t('loginError.generic.title'), description: t('loginError.generic.description'), diff --git a/src/oneid/oneid-fe/src/hooks/useLoginError.tsx b/src/oneid/oneid-fe/src/hooks/useLoginError.tsx index 602250fe..fbe36400 100644 --- a/src/oneid/oneid-fe/src/hooks/useLoginError.tsx +++ b/src/oneid/oneid-fe/src/hooks/useLoginError.tsx @@ -20,6 +20,7 @@ export enum ERROR_CODE { OI_ERROR = 'OI_ERROR', SESSION_ERROR = 'SESSION_ERROR', MISSING_REDIRECT_URI = 'CALLBACK_URI_NOT_FOUND', + GENERIC = 'GENERIC', } export const GENERIC_ERROR_DATA = { @@ -60,6 +61,7 @@ export const erroMap: Record = { [ERROR_CODE.OI_ERROR]: GENERIC_ERROR_DATA, [ERROR_CODE.SESSION_ERROR]: GENERIC_ERROR_DATA, [ERROR_CODE.MISSING_REDIRECT_URI]: GENERIC_ERROR_DATA, + [ERROR_CODE.GENERIC]: GENERIC_ERROR_DATA, }; export const useLoginError = () => { diff --git a/src/oneid/oneid-fe/src/pages/loginError/LoginError.tsx b/src/oneid/oneid-fe/src/pages/loginError/LoginError.tsx index 86f262be..9554b85a 100644 --- a/src/oneid/oneid-fe/src/pages/loginError/LoginError.tsx +++ b/src/oneid/oneid-fe/src/pages/loginError/LoginError.tsx @@ -6,7 +6,11 @@ import { LoadingOverlay } from '../../components/LoadingOverlay'; import Layout from '../../components/Layout'; import EndingPage from '../../components/EndingPage'; import { redirectToLogin } from '../../utils/utils'; -import { ErrorData, useLoginError } from '../../hooks/useLoginError'; +import { + ERROR_CODE, + ErrorData, + useLoginError, +} from '../../hooks/useLoginError'; export const LoginError = () => { const { t } = useTranslation(); @@ -15,12 +19,12 @@ export const LoginError = () => { const errorCode = new URLSearchParams(window.location.search).get( 'errorCode' - ); + ) as ERROR_CODE; const { handleErrorCode } = useLoginError(); const setContent = useCallback( - (errorCode: string) => { + (errorCode: ERROR_CODE) => { const { title, description } = handleErrorCode(errorCode); setErrorData({ title, description }); setLoading(false); @@ -30,7 +34,7 @@ export const LoginError = () => { useEffect(() => { setTimeout(() => { - setContent('generic'); + setContent(ERROR_CODE.GENERIC); }, 5 * 1000); }, [setContent]);