mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(ui): call error callback after async error handler (#3003)
This commit is contained in:
parent
53f49df621
commit
b5e7350ee9
3 changed files with 16 additions and 19 deletions
|
@ -46,12 +46,10 @@ const useContinueFlowCodeVerification = (
|
|||
|
||||
const verifyVerificationCodeErrorHandlers: ErrorHandlers = useMemo(
|
||||
() => ({
|
||||
'user.phone_already_in_use': () => {
|
||||
void identifierExistErrorHandler(SignInIdentifier.Phone, target);
|
||||
},
|
||||
'user.email_already_in_use': () => {
|
||||
void identifierExistErrorHandler(SignInIdentifier.Email, target);
|
||||
},
|
||||
'user.phone_already_in_use': async () =>
|
||||
identifierExistErrorHandler(SignInIdentifier.Phone, target),
|
||||
'user.email_already_in_use': async () =>
|
||||
identifierExistErrorHandler(SignInIdentifier.Email, target),
|
||||
...requiredProfileErrorHandler,
|
||||
...generalVerificationCodeErrorHandlers,
|
||||
callback: errorCallback,
|
||||
|
|
|
@ -24,9 +24,8 @@ const useForgotPasswordFlowCodeVerification = (
|
|||
|
||||
const errorHandlers: ErrorHandlers = useMemo(
|
||||
() => ({
|
||||
'user.user_not_exist': () => {
|
||||
void identifierErrorHandler(IdentifierErrorType.IdentifierNotExist, method, target);
|
||||
},
|
||||
'user.user_not_exist': async () =>
|
||||
identifierErrorHandler(IdentifierErrorType.IdentifierNotExist, method, target),
|
||||
'user.new_password_required_in_profile': () => {
|
||||
navigate(`/${UserFlow.forgotPassword}/reset`, { replace: true });
|
||||
},
|
||||
|
|
|
@ -13,9 +13,9 @@ type UseApi<T extends unknown[], U> = {
|
|||
};
|
||||
|
||||
export type ErrorHandlers = {
|
||||
[key in LogtoErrorCode]?: (error: RequestErrorBody) => void;
|
||||
[key in LogtoErrorCode]?: (error: RequestErrorBody) => void | Promise<void>;
|
||||
} & {
|
||||
global?: (error: RequestErrorBody) => void; // Overwrite default global error handle logic
|
||||
global?: (error: RequestErrorBody) => void | Promise<void>; // Overwrite default global error handle logic
|
||||
callback?: (error: RequestErrorBody) => void; // Callback method
|
||||
};
|
||||
|
||||
|
@ -77,15 +77,15 @@ function useApi<Args extends unknown[], Response>(
|
|||
const { code, message } = error;
|
||||
const handler = errorHandlers?.[code] ?? errorHandlers?.global;
|
||||
|
||||
errorHandlers?.callback?.(error);
|
||||
|
||||
(async () => {
|
||||
if (handler) {
|
||||
handler(error);
|
||||
|
||||
return;
|
||||
await handler(error);
|
||||
} else {
|
||||
setToast(message);
|
||||
}
|
||||
|
||||
setToast(message);
|
||||
errorHandlers?.callback?.(error);
|
||||
})();
|
||||
}, [error, errorHandlers, setToast, t]);
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue