From e41d6e3c46e84c661aa661116838dfe659d03008 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 18 Jul 2024 20:18:51 +0300 Subject: [PATCH] show default telegram error | remove sending error from api --- apps/api/src/ldap-tfa/ldap-tfa.controller.ts | 2 +- apps/web/components/Form/hooks/telegram.ts | 25 +++++++++----------- apps/web/constants/errors.ts | 1 + 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/apps/api/src/ldap-tfa/ldap-tfa.controller.ts b/apps/api/src/ldap-tfa/ldap-tfa.controller.ts index 84db787..1a914e4 100644 --- a/apps/api/src/ldap-tfa/ldap-tfa.controller.ts +++ b/apps/api/src/ldap-tfa/ldap-tfa.controller.ts @@ -79,7 +79,7 @@ export class LdapTfaController extends LdapController { }, }) .then((res) => reply.status(200).send(res.data)) - .catch((error) => reply.status(500).send(error.response.data)); + .catch(() => reply.status(500).send()); } @Get('/telegram-confirm') diff --git a/apps/web/components/Form/hooks/telegram.ts b/apps/web/components/Form/hooks/telegram.ts index 2e8c00f..a6cb604 100644 --- a/apps/web/components/Form/hooks/telegram.ts +++ b/apps/web/components/Form/hooks/telegram.ts @@ -1,11 +1,14 @@ import type { FormData } from '../lib/types'; import { useSocket } from './socket'; import { redirect } from '@/components/Form/lib/utils'; -import { ERROR_INVALID_CREDENTIALS, ERROR_SERVER } from '@/constants/errors'; +import { + ERROR_INVALID_CREDENTIALS, + ERROR_SERVER, + ERROR_TELEGRAM_SEND_MESSAGE, +} from '@/constants/errors'; import { FormStateContext } from '@/context/form-state'; -import type { TelegramUrlResponse } from '@/types/error'; import type { LdapUser } from '@/types/user'; -import axios, { isAxiosError } from 'axios'; +import axios from 'axios'; import { useContext, useEffect } from 'react'; export function useLogin() { @@ -48,18 +51,12 @@ export function useTelegramLogin() { type: 'set-step', }); }) - .catch((error_) => { - let error = ERROR_SERVER; - - if (isAxiosError(error_) && error_.response?.data?.message) { - error = error_.response?.data?.message; - } - - return dispatch({ - payload: { error }, + .catch(() => + dispatch({ + payload: { error: ERROR_TELEGRAM_SEND_MESSAGE }, type: 'set-error', - }); - }); + }) + ); } return { handleTelegramLogin }; diff --git a/apps/web/constants/errors.ts b/apps/web/constants/errors.ts index ca53a64..bb6fafb 100644 --- a/apps/web/constants/errors.ts +++ b/apps/web/constants/errors.ts @@ -1,2 +1,3 @@ export const ERROR_INVALID_CREDENTIALS = 'Неверный логин или пароль'; export const ERROR_SERVER = 'Не удалось войти. Повторите попытку позже'; +export const ERROR_TELEGRAM_SEND_MESSAGE = 'Не удалось отправить сообщение в Telegram';