-
Notifications
You must be signed in to change notification settings - Fork 2
фикс отсутствия ошибки при регистрации с невалидной почтой #343
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<F extends Func>( | |
|
|
||
| export function showErrorToast<F extends Func>( | ||
| method: F | ||
| ): Func<Promise<ReturnType<F>>, Parameters<F>> { | ||
| ): Func<Promise<{ error: any; response: ReturnType<F> | null }>, Parameters<F>> { | ||
| return async (...args: any[]) => { | ||
| const toastStore = useToastStore(); | ||
| try { | ||
| const response = await method(...args); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вот здесь и можно деструктурировать. const {error, response} = await method(...args); |
||
| return response; | ||
| } catch (err) { | ||
| const error = err as ApiError; | ||
| if ('error' in response) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Достаточно будет заменить на if (error) |
||
| const errormessage = response.error?.detail?.[0].msg; | ||
| throw new Error(errormessage); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Лучше здесь сделать throw error;и обрабатывать все уже в catch |
||
| } 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<F extends Func>( | |
| type: ToastType.Error, | ||
| }); | ||
| } | ||
| return { error: err, response: null }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не стоит менять формат выходных данных, сложно обрабатывать потом будет. Давай здесь возвращать undefined
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ты, по сути, уже обработал ошибку, дальше ее прокидывать не нужно. |
||
| } | ||
| }; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вот здесь с типами не нужно запариваться
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Когда уберешь сложную конструкцию в конце, можно будет вернуть старые типы и все будет хорошо