improvement: error handeling structure changed and unified all across the app. user no longer sees inappropriate messages.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { useCallback, useEffect, useState, type KeyboardEvent } from 'react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { Eye, EyeOff, Send } from 'lucide-react';
|
||||
import { formatApiErrorMessage } from '@/components/shared/formatApiError';
|
||||
import { getUserFacingError } from '@/components/shared/formatApiError';
|
||||
import type { LabCaseComment } from '@/types/cases';
|
||||
|
||||
interface LabCaseCommentsPanelProps {
|
||||
@@ -36,6 +36,7 @@ export function LabCaseCommentsPanel({
|
||||
onComposerValueChange,
|
||||
}: LabCaseCommentsPanelProps) {
|
||||
const t = useTranslations('caseComments');
|
||||
const tErrors = useTranslations('errors');
|
||||
const [comments, setComments] = useState<LabCaseComment[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [posting, setPosting] = useState(false);
|
||||
@@ -48,7 +49,7 @@ export function LabCaseCommentsPanel({
|
||||
const items = await loadComments();
|
||||
setComments(items);
|
||||
} catch (error: unknown) {
|
||||
onError?.(formatApiErrorMessage(error, t('errorLoad')));
|
||||
onError?.(getUserFacingError(error, tErrors, t('errorLoad')));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -68,7 +69,7 @@ export function LabCaseCommentsPanel({
|
||||
setBody('');
|
||||
setVisibleToClinic(false);
|
||||
} catch (error: unknown) {
|
||||
onError?.(formatApiErrorMessage(error, t('errorPost')));
|
||||
onError?.(getUserFacingError(error, tErrors, t('errorPost')));
|
||||
} finally {
|
||||
setPosting(false);
|
||||
}
|
||||
@@ -87,7 +88,7 @@ export function LabCaseCommentsPanel({
|
||||
const updated = await onToggleVisibility(comment.id, !comment.visibleToClinic);
|
||||
setComments((prev) => prev.map((c) => (c.id === updated.id ? updated : c)));
|
||||
} catch (error: unknown) {
|
||||
onError?.(formatApiErrorMessage(error, t('errorToggle')));
|
||||
onError?.(getUserFacingError(error, tErrors, t('errorToggle')));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user