feat: integrate error handling across various components

- Added `useErrorHandler` hook to centralize error handling logic.
- Updated components in the backoffice and portal applications to utilize the new error handling mechanism, replacing direct notify calls with `handleError` for improved error messaging.
- Enhanced localization files to include generic error messages for better user feedback.
- Refactored error handling in forms and API interactions to ensure consistent user experience across the application.
This commit is contained in:
estifanos
2026-07-24 09:08:41 +00:00
parent 4ccf27c044
commit 8f7c163b9e
28 changed files with 229 additions and 121 deletions

View File

@@ -22,7 +22,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { Link } from 'react-router-dom';
import { useApiMutation } from '@ema-platform/api';
import { notify } from '@ema-platform/ui';
import { notify, useErrorHandler } from '@ema-platform/ui';
import { AuthShell } from '../components/AuthShell';
import { useAuthConfig } from '../AuthConfig';
@@ -37,6 +37,7 @@ export function ForgotPasswordPage() {
const [forgotTrigger, { isLoading }] = useApiMutation();
const [sentTo, setSentTo] = useState<string | null>(null);
const [serverError, setServerError] = useState<string | null>(null);
const { handleError } = useErrorHandler();
const {
register,
@@ -59,11 +60,7 @@ export function ForgotPasswordPage() {
try {
await sendResetLink(values.email);
} catch (err: unknown) {
const msg =
(err as { data?: { message?: string } })?.data?.message ??
(err instanceof Error ? err.message : 'Something went wrong');
setServerError(msg);
notify.error(msg);
setServerError(handleError(err));
}
};
@@ -73,11 +70,7 @@ export function ForgotPasswordPage() {
await sendResetLink(sentTo);
notify.success('Reset link sent again');
} catch (err: unknown) {
const msg =
(err as { data?: { message?: string } })?.data?.message ??
(err instanceof Error ? err.message : 'Something went wrong');
setServerError(msg);
notify.error(msg);
setServerError(handleError(err));
}
};