fix(audit-tier-2): error-surface hygiene — toastError + CodedError sweep

Two mechanical sweeps closing the audit's HIGH §16 + MED §11 findings:

* 38 client components / 56 toast.error sites converted to
  toastError(err) so the new admin error inspector becomes usable from
  user-reported issues — every failed inline-edit, save, send, archive,
  upload, etc. now carries the request-id + error-code (Copy ID action).
* 26 service files / 62 bare-Error throws converted to CodedError or
  the existing AppError subclasses.  Adds new error codes:
  DOCUMENSO_UPSTREAM_ERROR (502), DOCUMENSO_AUTH_FAILURE (502),
  DOCUMENSO_TIMEOUT (504), OCR_UPSTREAM_ERROR (502),
  IMAP_UPSTREAM_ERROR (502), UMAMI_UPSTREAM_ERROR (502),
  UMAMI_NOT_CONFIGURED (409), and INSERT_RETURNING_EMPTY (500) for
  post-insert returning-empty guards.
* Five vitest assertions updated to match the new user-facing wording
  (client-merge "already been merged", expense/interest "couldn't find
  that …", documenso "signing service didn't respond").

Test status: 1168/1168 vitest, tsc clean.

Refs: docs/audit-comprehensive-2026-05-05.md HIGH §16 (auditor-H Issue 1)
+ MED §11 (auditor-G Issue 1).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Ciaccio
2026-05-05 20:18:05 +02:00
parent 6a609ecf94
commit fc7595faf8
69 changed files with 426 additions and 166 deletions

View File

@@ -11,6 +11,7 @@ import { CountryCombobox } from '@/components/shared/country-combobox';
import { SubdivisionCombobox } from '@/components/shared/subdivision-combobox';
import { InlineEditableField } from '@/components/shared/inline-editable-field';
import { apiFetch } from '@/lib/api/client';
import { toastError } from '@/lib/api/toast-error';
import type { CountryCode } from '@/lib/i18n/countries';
import { getCountryName } from '@/lib/i18n/countries';
import { getSubdivisionName } from '@/lib/i18n/subdivisions';
@@ -119,7 +120,7 @@ function AddressCard({
try {
await onUpdate({ isPrimary: true });
} catch (err) {
toast.error(err instanceof Error ? err.message : 'Failed to update');
toastError(err);
}
}
@@ -362,7 +363,7 @@ function NewAddressForm({
isPrimary: makePrimary,
});
} catch (err) {
toast.error(err instanceof Error ? err.message : 'Failed to add address');
toastError(err);
} finally {
setSaving(false);
}

View File

@@ -2,9 +2,9 @@
import { useRef, useState } from 'react';
import { Loader2, Pencil } from 'lucide-react';
import { toast } from 'sonner';
import { CountryCombobox } from '@/components/shared/country-combobox';
import { toastError } from '@/lib/api/toast-error';
import { getCountryName, type CountryCode } from '@/lib/i18n/countries';
import { cn } from '@/lib/utils';
@@ -46,7 +46,7 @@ export function InlineCountryField({
await onSave(next);
setEditing(false);
} catch (err) {
toast.error(err instanceof Error ? err.message : 'Failed to save');
toastError(err);
} finally {
setSaving(false);
}

View File

@@ -2,8 +2,8 @@
import { useEffect, useRef, useState } from 'react';
import { Loader2, Pencil } from 'lucide-react';
import { toast } from 'sonner';
import { toastError } from '@/lib/api/toast-error';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import {
@@ -85,7 +85,7 @@ export function InlineEditableField(props: InlineEditableFieldProps) {
await onSave(trimmed === '' ? null : trimmed);
setEditing(false);
} catch (err) {
toast.error(err instanceof Error ? err.message : 'Failed to save');
toastError(err);
setDraft(value ?? '');
} finally {
setSaving(false);

View File

@@ -2,9 +2,9 @@
import { useState } from 'react';
import { Loader2, Pencil } from 'lucide-react';
import { toast } from 'sonner';
import { PhoneInput, type PhoneInputValue } from '@/components/shared/phone-input';
import { toastError } from '@/lib/api/toast-error';
import { parsePhone } from '@/lib/i18n/phone';
import type { CountryCode } from '@/lib/i18n/countries';
import { cn } from '@/lib/utils';
@@ -66,7 +66,7 @@ export function InlinePhoneField({
await onSave(next);
setEditing(false);
} catch (err) {
toast.error(err instanceof Error ? err.message : 'Failed to save');
toastError(err);
} finally {
setSaving(false);
}

View File

@@ -3,11 +3,11 @@
import { useState } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { Plus, X, Check } from 'lucide-react';
import { toast } from 'sonner';
import { Button } from '@/components/ui/button';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import { apiFetch } from '@/lib/api/client';
import { toastError } from '@/lib/api/toast-error';
import { cn } from '@/lib/utils';
interface Tag {
@@ -45,7 +45,7 @@ export function InlineTagEditor({
const setTags = useMutation({
mutationFn: (tagIds: string[]) => apiFetch(endpoint, { method: 'PUT', body: { tagIds } }),
onSuccess: () => qc.invalidateQueries({ queryKey: invalidateKey }),
onError: (err) => toast.error(err instanceof Error ? err.message : 'Failed to update tags'),
onError: (err) => toastError(err),
});
function toggleTag(tagId: string) {

View File

@@ -2,9 +2,9 @@
import { useRef, useState } from 'react';
import { Loader2, Pencil } from 'lucide-react';
import { toast } from 'sonner';
import { TimezoneCombobox } from '@/components/shared/timezone-combobox';
import { toastError } from '@/lib/api/toast-error';
import { formatTimezoneLabel } from '@/lib/i18n/timezones';
import type { CountryCode } from '@/lib/i18n/countries';
import { cn } from '@/lib/utils';
@@ -46,7 +46,7 @@ export function InlineTimezoneField({
await onSave(next);
setEditing(false);
} catch (err) {
toast.error(err instanceof Error ? err.message : 'Failed to save');
toastError(err);
} finally {
setSaving(false);
}

View File

@@ -33,6 +33,7 @@ import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import { Input } from '@/components/ui/input';
import { apiFetch } from '@/lib/api/client';
import { toastError } from '@/lib/api/toast-error';
const BODY_MAX = 50_000;
@@ -149,7 +150,7 @@ export function SendDocumentDialog({
}
},
onError: (err) => {
toast.error(err instanceof Error ? err.message : 'Send failed');
toastError(err);
},
});