diff --git a/apps/api/src/ldap-tfa/ldap-tfa.controller.ts b/apps/api/src/ldap-tfa/ldap-tfa.controller.ts index c9004c4..401526d 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)); + .catch((error) => reply.status(500).send(error.response.data)); } @Get('/telegram-confirm') diff --git a/apps/web/components/Form.tsx b/apps/web/components/Form.tsx index b70217c..52950ed 100644 --- a/apps/web/components/Form.tsx +++ b/apps/web/components/Form.tsx @@ -5,8 +5,9 @@ import styles from './Form.module.scss'; import { publicRuntimeConfig } from '@/config/runtime'; import { FormStateContext } from '@/context/form-state'; import { useSocket } from '@/hooks/socket'; +import type { TelegramUrlResponse } from '@/types/error'; import type { LdapUser } from '@/types/user'; -import axios from 'axios'; +import axios, { isAxiosError } from 'axios'; import Image from 'next/image'; import type { PropsWithChildren } from 'react'; import { useContext, useEffect } from 'react'; @@ -157,12 +158,18 @@ export const Form = { type: 'set-step', }); }) - .catch(() => - dispatch({ - payload: { error: ERROR_SERVER }, + .catch((error_) => { + let error = ERROR_SERVER; + + if (isAxiosError(error_) && error_.response?.data?.message) { + error = error_.response?.data?.message; + } + + return dispatch({ + payload: { error }, type: 'set-error', - }) - ); + }); + }); } if (step === 'telegram') { diff --git a/apps/web/types/error.ts b/apps/web/types/error.ts new file mode 100644 index 0000000..4376bfe --- /dev/null +++ b/apps/web/types/error.ts @@ -0,0 +1,3 @@ +export type TelegramUrlResponse = { + message: string; +};