improvement: error handeling structure changed and unified all across the app. user no longer sees inappropriate messages.

This commit is contained in:
2026-07-12 18:27:38 +03:30
parent 901d838a2c
commit fab5111aa8
45 changed files with 977 additions and 241 deletions

View File

@@ -5,7 +5,7 @@ import { useTranslations } from 'next-intl';
import { Button } from '@/components/ui/shared/Button';
import { ToastStack } from '@/components/ui/shared/Toast';
import { patientsApi } from '@/lib/api/patients';
import { formatApiErrorMessage } from '@/components/shared/formatApiError';
import { getUserFacingError } from '@/components/shared/formatApiError';
import { useAuth } from '@/lib/hooks/useAuth';
import { useToast } from '@/lib/hooks/useToast';
import { hasPermission } from '@/components/shared/permissions';
@@ -23,6 +23,7 @@ const EMPTY_PATIENT_FORM: CreatePatientInput = {
export default function PatientsPage() {
const t = useTranslations('patients');
const tErrors = useTranslations('errors');
const tCommon = useTranslations('common');
const { currentOrganization } = useAuth();
const toast = useToast();
@@ -67,7 +68,7 @@ export default function PatientsPage() {
setSelectedPatient(freshSelected);
}
} catch (error: unknown) {
toast.showError(formatApiErrorMessage(error, t('errorLoadPatients')));
toast.showError(getUserFacingError(error, tErrors, t('errorLoadPatients')));
} finally {
setLoadingPatients(false);
}
@@ -98,7 +99,7 @@ export default function PatientsPage() {
);
}
} catch (error: unknown) {
toast.showError(formatApiErrorMessage(error, t('errorSavePatient')));
toast.showError(getUserFacingError(error, tErrors, t('errorSavePatient')));
} finally {
setSavingPatient(false);
}