0
Fork 0
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:
simeng-li 2023-01-28 15:58:25 +08:00 committed by GitHub
parent 53f49df621
commit b5e7350ee9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 19 deletions

View file

@ -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,

View file

@ -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 });
},

View file

@ -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) {
await handler(error);
} else {
setToast(message);
}
if (handler) {
handler(error);
return;
}
setToast(message);
errorHandlers?.callback?.(error);
})();
}, [error, errorHandlers, setToast, t]);
return {