refactor(web): consolidate error-copy table to JSON source of truth

Three admin pages had divergent inline error-code → user-copy switch
tables (with wording drift, including a stale "Settings → Integrations"
that should have been Admin). Consolidate into web/src/lib/styles/error-copy.json,
expose via web/src/lib/api/error-copy.ts (ERROR_COPY + copyForCode),
and refactor the three pages to import the helper.

Fixes the three-way drift; the only user-visible behavior change is
the quarantine page now correctly says "Admin → Integrations".

Sets up the JSON for the M7 Flutter client (#356) to consume the same
table.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-02 15:01:46 -04:00
parent ea22807a3f
commit c3be0f3e6e
6 changed files with 40 additions and 68 deletions
+3 -25
View File
@@ -8,6 +8,7 @@
approveRequest,
rejectRequest
} from '$lib/api/admin';
import { copyForCode } from '$lib/api/error-copy';
import StatusPill from '$lib/components/StatusPill.svelte';
import type { LidarrRequest, LidarrRequestKind, LidarrRequestStatus } from '$lib/api/types';
@@ -67,29 +68,6 @@
}, 5000);
}
function errorCopy(code: string): string {
switch (code) {
case 'lidarr_unreachable':
return "Lidarr is unreachable right now. Try again, or check Admin → Integrations.";
case 'lidarr_disabled':
return 'Lidarr integration is not enabled.';
case 'lidarr_auth_failed':
return 'Lidarr authentication failed.';
case 'lidarr_defaults_incomplete':
return 'Lidarr is missing a default quality profile or root folder. Set them in Admin → Integrations.';
case 'lidarr_server_error':
return "Lidarr returned an error. Check Lidarr's logs for the cause.";
case 'lidarr_rejected':
return "Lidarr rejected the request. Check the server logs for the field-level reason.";
case 'request_not_pending':
return 'This request is no longer pending.';
case 'request_not_found':
return 'That request no longer exists.';
default:
return code ? code : "Couldn't reach Lidarr.";
}
}
function fallbackIcon(kind: LidarrRequestKind) {
if (kind === 'artist') return Disc3;
if (kind === 'album') return Album;
@@ -136,7 +114,7 @@
await invalidate();
} catch (e) {
const code = (e as { code?: string }).code ?? 'unknown';
showToast(errorCopy(code));
showToast(copyForCode(code));
}
}
@@ -177,7 +155,7 @@
await invalidate();
} catch (e) {
const code = (e as { code?: string }).code ?? 'unknown';
showToast(errorCopy(code));
showToast(copyForCode(code));
}
}