improvement: error handeling structure changed and unified all across the app. user no longer sees inappropriate messages.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { formatApiErrorMessage } from '@/components/shared/formatApiError';
|
||||
import { getUserFacingError } from '@/components/shared/formatApiError';
|
||||
import { canEditCases } from '@/components/shared/permissions';
|
||||
import { useAuth } from '@/lib/hooks/useAuth';
|
||||
import { useToast } from '@/lib/hooks/useToast';
|
||||
@@ -37,6 +37,7 @@ export function ConnectionCaseHistoryContent({
|
||||
onBack,
|
||||
}: ConnectionCaseHistoryContentProps) {
|
||||
const t = useTranslations('organizations');
|
||||
const tErrors = useTranslations('errors');
|
||||
const tCases = useTranslations('cases');
|
||||
const tCommon = useTranslations('common');
|
||||
const { currentOrganization, user } = useAuth();
|
||||
@@ -102,7 +103,7 @@ export function ConnectionCaseHistoryContent({
|
||||
setPagination(response.data.pagination);
|
||||
} catch (error: unknown) {
|
||||
if (cancelled) return;
|
||||
showError(formatApiErrorMessage(error, tRef.current('caseHistoryErrorLoadList')));
|
||||
showError(getUserFacingError(error, tErrors, tRef.current('caseHistoryErrorLoadList')));
|
||||
} finally {
|
||||
if (!cancelled) setLoadingList(false);
|
||||
}
|
||||
@@ -142,7 +143,7 @@ export function ConnectionCaseHistoryContent({
|
||||
setSelectedCase(response.data);
|
||||
} catch (error: unknown) {
|
||||
if (cancelled) return;
|
||||
showError(formatApiErrorMessage(error, tRef.current('caseHistoryErrorLoadDetail')));
|
||||
showError(getUserFacingError(error, tErrors, tRef.current('caseHistoryErrorLoadDetail')));
|
||||
setSelectedCase(null);
|
||||
} finally {
|
||||
if (!cancelled) setLoadingDetail(false);
|
||||
@@ -182,7 +183,7 @@ export function ConnectionCaseHistoryContent({
|
||||
setSelectedCase(response.data);
|
||||
} catch (error: unknown) {
|
||||
setSelectedCase(previousCase);
|
||||
showError(formatApiErrorMessage(error, tCases('errorUpdateTask')));
|
||||
showError(getUserFacingError(error, tErrors, tCases('errorUpdateTask')));
|
||||
} finally {
|
||||
setUpdatingImportant(false);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { getUserFacingError } from '@/components/shared/formatApiError';
|
||||
import { useAuth } from '@/lib/hooks/useAuth';
|
||||
import { canCreateOrganizationFromCurrentOrg } from '@/components/shared/permissions';
|
||||
import { Building2, Beaker, Mail } from 'lucide-react';
|
||||
@@ -12,13 +13,14 @@ export function OrganizationSelectorContent() {
|
||||
const t = useTranslations('organizations');
|
||||
const tAuth = useTranslations('auth');
|
||||
const tCommon = useTranslations('common');
|
||||
const tErrors = useTranslations('errors');
|
||||
const {
|
||||
organizations,
|
||||
currentOrganization,
|
||||
selectOrganization,
|
||||
createOrganization,
|
||||
isLoading,
|
||||
error,
|
||||
apiError,
|
||||
clearError,
|
||||
} = useAuth();
|
||||
const canCreateOrganization = useMemo(
|
||||
@@ -82,6 +84,12 @@ export function OrganizationSelectorContent() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{apiError && (
|
||||
<div className="p-3 bg-red-950/30 border border-red-600/40 rounded-[var(--radius-md)]">
|
||||
<p className="text-sm text-red-600">{getUserFacingError(apiError, tErrors)}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{canCreateOrganization && isCreateOpen && (
|
||||
<div className="surface-card p-4 sm:p-6 space-y-4">
|
||||
<Input
|
||||
@@ -128,11 +136,6 @@ export function OrganizationSelectorContent() {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{error && (
|
||||
<div className="p-3 bg-red-950/30 border border-red-600/40 rounded-[var(--radius-md)]">
|
||||
<p className="text-sm text-red-600">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-col sm:flex-row sm:justify-end">
|
||||
<Button
|
||||
type="button"
|
||||
|
||||
Reference in New Issue
Block a user