diff --git a/src/api/controllers/auth/decorators.ts b/src/api/controllers/auth/decorators.ts index 8f0791d..9690509 100644 --- a/src/api/controllers/auth/decorators.ts +++ b/src/api/controllers/auth/decorators.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { ApiError } from '@/api'; import { apiClient } from '../../client'; import { ToastType } from '@/models'; import router from '@/router'; @@ -37,17 +36,22 @@ export function scoped( export function showErrorToast( method: F -): Func>, Parameters> { +): Func | null }>, Parameters> { return async (...args: any[]) => { const toastStore = useToastStore(); try { const response = await method(...args); - return response; - } catch (err) { - const error = err as ApiError; + if ('error' in response) { + const errormessage = response.error?.detail?.[0].msg; + throw new Error(errormessage); + } else { + return response; + } + } catch (err: any) { + const error = err?.detail?.[0] ?? err; if (error) { toastStore.push({ - title: error.ru ?? error.message, + title: error.ru ?? error.msg ?? error, type: ToastType.Error, }); } else { @@ -57,6 +61,7 @@ export function showErrorToast( type: ToastType.Error, }); } + return { error: err, response: null }; } }; }