Skip to content

фикс отсутствия ошибки при регистрации с невалидной почтой#343

Open
r1m199 wants to merge 3 commits intoprofcomff:mainfrom
r1m199:fix-email-reg
Open

фикс отсутствия ошибки при регистрации с невалидной почтой#343
r1m199 wants to merge 3 commits intoprofcomff:mainfrom
r1m199:fix-email-reg

Conversation

@r1m199
Copy link
Copy Markdown

@r1m199 r1m199 commented Apr 16, 2026

Действовал по шагам:
Деструктурировать ответ method как {error, response}
Если есть error, то пробросить error
Обозначить переменную error в блоке catch на выражение: err?.detail?.[0]?? err;
В toastStore.push в поле title добавить ?? error.msg ?? error
В итоге должен показываться тост с Value error,

Пришлось добавить err: any в catch, так как было неизвестно, есть ли detail у него
выброс ошибки возможно реализован коряво

Check-List

  • [V] Вы проверили свой код перед отправкой запроса?
  • [?] Вы написали тесты к реализованным функциям?
  • [?] Вы не забыли применить форматирование black и isort для Back-End или Prettier для Front-End?

return async (...args: any[]) => {
const toastStore = useToastStore();
try {
const response = await method(...args);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот здесь и можно деструктурировать.

const {error, response} = await method(...args);

export function showErrorToast<F extends Func>(
method: F
): Func<Promise<ReturnType<F>>, Parameters<F>> {
): Func<Promise<{ error: any; response: ReturnType<F> | null }>, Parameters<F>> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот здесь с типами не нужно запариваться

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Когда уберешь сложную конструкцию в конце, можно будет вернуть старые типы и все будет хорошо

type: ToastType.Error,
});
}
return { error: err, response: null };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не стоит менять формат выходных данных, сложно обрабатывать потом будет. Давай здесь возвращать undefined

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ты, по сути, уже обработал ошибку, дальше ее прокидывать не нужно.

return response;
} catch (err) {
const error = err as ApiError;
if ('error' in response) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Достаточно будет заменить на

if (error)

const error = err as ApiError;
if ('error' in response) {
const errormessage = response.error?.detail?.[0].msg;
throw new Error(errormessage);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше здесь сделать

throw error;

и обрабатывать все уже в catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] отсутствие уведомления об использовании не валидной почты при регистрации

2 participants