diff --git a/src/ui/components/userDetail/userDetailForm.tsx b/src/ui/components/userDetail/userDetailForm.tsx index c36ea006..d4ecabc3 100644 --- a/src/ui/components/userDetail/userDetailForm.tsx +++ b/src/ui/components/userDetail/userDetailForm.tsx @@ -290,29 +290,27 @@ export const UserDetailChangeEmailForm: FC = ( return; } - let response; - try { - response = await updateUserInformation({ + const response = await updateUserInformation({ userId, email, recipeId, tenantId, }); + + if (response.status === "INVALID_EMAIL_ERROR") { + setApiError(response.error); + } else if (response.status === "EMAIL_ALREADY_EXISTS_ERROR") { + setApiError("A user with this email already exists"); + } else if (response.status === "OK") { + showToast(getUpdateEmailToast(true)); + await onEmailChange(true); + } } catch (error) { if (ForbiddenError.isThisError(error)) { void onCancel(); } } - - if (response?.status === "INVALID_EMAIL_ERROR") { - setApiError(response.error); - } else if (response?.status === "EMAIL_ALREADY_EXISTS_ERROR") { - setApiError("A user with this email already exists"); - } else if (response?.status === "OK") { - showToast(getUpdateEmailToast(true)); - await onEmailChange(true); - } }; const onCancel = async () => { @@ -392,26 +390,24 @@ export const UserDetailChangePasswordForm: FC return; } - let response; - try { - response = await updatePassword( + const response = await updatePassword( userId, password, matchingTenantIds.length > 0 ? matchingTenantIds[0].tenantId : undefined ); + + if (response?.status === "INVALID_PASSWORD_ERROR") { + setApiError(response.error); + } else if (response?.status === "OK") { + showToast(getUpdatePasswordToast(true)); + await onPasswordChange(); + } } catch (error) { if (ForbiddenError.isThisError(error)) { void onCancel(); } } - - if (response?.status === "INVALID_PASSWORD_ERROR") { - setApiError(response.error); - } else if (response?.status === "OK") { - showToast(getUpdatePasswordToast(true)); - await onPasswordChange(); - } }; const onCancel = async () => { diff --git a/src/utils/index.ts b/src/utils/index.ts index 1de92625..14be0994 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -131,6 +131,10 @@ export const useFetchData = () => { } window.dispatchEvent(getAccessDeniedEvent(message)); + /* throwing this error just to make sure that this case is handled in some places in the application. + global search for ForbiddenError.isThisError to see those places + */ + throw new ForbiddenError(message); }