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

fix: useLoginError now has different type to represent an error #585

Merged
merged 1 commit into from
Jan 7, 2025
Merged
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
22 changes: 12 additions & 10 deletions src/oneid/oneid-fe/src/hooks/useLoginError.test.tsx
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down
2 changes: 2 additions & 0 deletions src/oneid/oneid-fe/src/hooks/useLoginError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -60,6 +61,7 @@ export const erroMap: Record<ERROR_CODE, ErrorData> = {
[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 = () => {
Expand Down
12 changes: 8 additions & 4 deletions src/oneid/oneid-fe/src/pages/loginError/LoginError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -30,7 +34,7 @@ export const LoginError = () => {

useEffect(() => {
setTimeout(() => {
setContent('generic');
setContent(ERROR_CODE.GENERIC);
}, 5 * 1000);
}, [setContent]);

Expand Down
Loading