refactor(web/api): errCode + errMessage helpers; 41 sites migrated (W1)
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
type ScanScheduleMode
|
||||
} from '$lib/api/admin';
|
||||
import { qk } from '$lib/api/queries';
|
||||
import { copyForCode } from '$lib/api/error-copy';
|
||||
import { errCode, errMessage } from '$lib/api/errors';
|
||||
import type {
|
||||
AdminQuarantineRow,
|
||||
LidarrRequest,
|
||||
@@ -132,7 +132,7 @@
|
||||
await approveRequest(r.id);
|
||||
await invalidateRequests();
|
||||
} catch (e) {
|
||||
showToast(copyForCode((e as { code?: string }).code));
|
||||
showToast(errMessage(e));
|
||||
}
|
||||
}
|
||||
async function onReject(r: LidarrRequest) {
|
||||
@@ -140,7 +140,7 @@
|
||||
await rejectRequest(r.id);
|
||||
await invalidateRequests();
|
||||
} catch (e) {
|
||||
showToast(copyForCode((e as { code?: string }).code));
|
||||
showToast(errMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@
|
||||
await resolveQuarantine(row.track_id);
|
||||
await invalidateQuarantine();
|
||||
} catch (e) {
|
||||
showToast(copyForCode((e as { code?: string }).code));
|
||||
showToast(errMessage(e));
|
||||
}
|
||||
}
|
||||
async function onDeleteFile(row: AdminQuarantineRow) {
|
||||
@@ -170,7 +170,7 @@
|
||||
await deleteQuarantineFile(row.track_id);
|
||||
await invalidateQuarantine();
|
||||
} catch (e) {
|
||||
showToast(copyForCode((e as { code?: string }).code));
|
||||
showToast(errMessage(e));
|
||||
}
|
||||
}
|
||||
async function onDeleteLidarr(row: AdminQuarantineRow) {
|
||||
@@ -184,7 +184,7 @@
|
||||
await deleteQuarantineViaLidarr(row.track_id);
|
||||
await invalidateQuarantine();
|
||||
} catch (e) {
|
||||
showToast(copyForCode((e as { code?: string }).code));
|
||||
showToast(errMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@
|
||||
await client.invalidateQueries({ queryKey: qk.scanStatus() });
|
||||
await client.invalidateQueries({ queryKey: qk.coverage() });
|
||||
} catch (e) {
|
||||
const code = (e as { code?: string; status?: number })?.code ?? 'unknown';
|
||||
const code = errCode(e);
|
||||
const status = (e as { status?: number })?.status;
|
||||
if (status === 409) {
|
||||
triggerResult = 'A scan is already running.';
|
||||
@@ -286,7 +286,7 @@
|
||||
await updateScanSchedule(patch);
|
||||
await client.invalidateQueries({ queryKey: qk.scanSchedule() });
|
||||
} catch (e) {
|
||||
showToast(`Schedule save failed: ${(e as { code?: string })?.code ?? 'unknown'}`);
|
||||
showToast(`Schedule save failed: ${errCode(e)}`);
|
||||
} finally {
|
||||
scheduleSaving = false;
|
||||
}
|
||||
@@ -325,7 +325,7 @@
|
||||
await researchMissingArt();
|
||||
showToast('All previously-failed art will be re-attempted on the next scan.');
|
||||
} catch (e) {
|
||||
showToast(`Re-search failed: ${(e as { code?: string })?.code ?? 'unknown'}`);
|
||||
showToast(`Re-search failed: ${errCode(e)}`);
|
||||
} finally {
|
||||
researchSaving = false;
|
||||
}
|
||||
@@ -340,7 +340,7 @@
|
||||
bulkResult = `Queued ${queued} albums for cover refetch.`;
|
||||
await client.invalidateQueries({ queryKey: qk.coverage() });
|
||||
} catch (e) {
|
||||
bulkResult = `Failed: ${(e as { code?: string })?.code ?? 'unknown'}`;
|
||||
bulkResult = `Failed: ${errCode(e)}`;
|
||||
} finally {
|
||||
bulkBusy = false;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
type SMTPConfig
|
||||
} from '$lib/api/admin';
|
||||
import { qk } from '$lib/api/queries';
|
||||
import { errCode } from '$lib/api/errors';
|
||||
import type { LidarrConfig, LidarrTestResult } from '$lib/api/types';
|
||||
|
||||
// Lidarr connection panel. The "saved api key" is masked as "***" on GET —
|
||||
@@ -112,7 +113,8 @@
|
||||
]);
|
||||
apiKeyInput = '';
|
||||
} catch (e) {
|
||||
saveError = (e as { code?: string }).code ?? 'save_failed';
|
||||
const code = errCode(e);
|
||||
saveError = code === 'unknown' ? 'save_failed' : code;
|
||||
} finally {
|
||||
isSaving = false;
|
||||
}
|
||||
@@ -160,7 +162,8 @@
|
||||
modalOpen = false;
|
||||
disconnectInput = '';
|
||||
} catch (e) {
|
||||
disconnectError = (e as { code?: string }).code ?? 'disconnect_failed';
|
||||
const code = errCode(e);
|
||||
disconnectError = code === 'unknown' ? 'disconnect_failed' : code;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,9 +273,9 @@
|
||||
smtpPasswordInput = '';
|
||||
showToast('SMTP config saved.');
|
||||
} catch (e: unknown) {
|
||||
const code = (e as { code?: string })?.code;
|
||||
const code = errCode(e);
|
||||
if (code === 'missing_fields') showToast('Host and from address are required when enabled.');
|
||||
else showToast(`Save failed: ${code ?? 'unknown'}`);
|
||||
else showToast(`Save failed: ${code}`);
|
||||
} finally {
|
||||
smtpSaving = false;
|
||||
}
|
||||
@@ -284,12 +287,12 @@
|
||||
await testSMTPConfig();
|
||||
showToast('Test email sent. Check your inbox.');
|
||||
} catch (e: unknown) {
|
||||
const code = (e as { code?: string })?.code;
|
||||
const code = errCode(e);
|
||||
const message = (e as { message?: string })?.message;
|
||||
if (code === 'no_email_on_file') showToast('Set your email in /settings before testing.');
|
||||
else if (code === 'not_configured') showToast('Save the SMTP config first.');
|
||||
else if (code === 'send_failed') showToast(`Send failed: ${message || 'see server logs'}`);
|
||||
else showToast(`Test failed: ${code ?? 'unknown'}`);
|
||||
else showToast(`Test failed: ${code}`);
|
||||
} finally {
|
||||
smtpTesting = false;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
deleteQuarantineViaLidarr
|
||||
} from '$lib/api/admin';
|
||||
import { qk } from '$lib/api/queries';
|
||||
import { copyForCode } from '$lib/api/error-copy';
|
||||
import { errMessage } from '$lib/api/errors';
|
||||
import { playRadio } from '$lib/player/store.svelte';
|
||||
import type { AdminQuarantineRow, LidarrQuarantineReason } from '$lib/api/types';
|
||||
|
||||
@@ -89,8 +89,7 @@
|
||||
await resolveQuarantine(r.track_id);
|
||||
await invalidate();
|
||||
} catch (e) {
|
||||
const code = (e as { code?: string }).code ?? 'unknown';
|
||||
showToast(copyForCode(code));
|
||||
showToast(errMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +107,7 @@
|
||||
await deleteQuarantineFile(r.track_id);
|
||||
await invalidate();
|
||||
} catch (e) {
|
||||
const code = (e as { code?: string }).code ?? 'unknown';
|
||||
showToast(copyForCode(code));
|
||||
showToast(errMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,12 +133,12 @@
|
||||
deleteLidarrError = null;
|
||||
await invalidate();
|
||||
} catch (e) {
|
||||
const code = (e as { code?: string }).code ?? 'unknown';
|
||||
const msg = errMessage(e);
|
||||
// Inline error keeps the modal open so the operator sees the failure
|
||||
// alongside the album they were about to remove.
|
||||
deleteLidarrError = copyForCode(code);
|
||||
deleteLidarrError = msg;
|
||||
// Also surface as toast so it's visible after dismissing the modal.
|
||||
showToast(copyForCode(code));
|
||||
showToast(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
approveRequest,
|
||||
rejectRequest
|
||||
} from '$lib/api/admin';
|
||||
import { copyForCode } from '$lib/api/error-copy';
|
||||
import { errMessage } from '$lib/api/errors';
|
||||
import StatusPill from '$lib/components/StatusPill.svelte';
|
||||
import type { LidarrRequest, LidarrRequestKind, LidarrRequestStatus } from '$lib/api/types';
|
||||
|
||||
@@ -114,8 +114,7 @@
|
||||
}
|
||||
await invalidate();
|
||||
} catch (e) {
|
||||
const code = (e as { code?: string }).code ?? 'unknown';
|
||||
showToast(copyForCode(code));
|
||||
showToast(errMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,8 +154,7 @@
|
||||
await rejectRequest(r.id, notes ? notes : undefined);
|
||||
await invalidate();
|
||||
} catch (e) {
|
||||
const code = (e as { code?: string }).code ?? 'unknown';
|
||||
showToast(copyForCode(code));
|
||||
showToast(errMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
type AdminInvite,
|
||||
type CreateUserInput
|
||||
} from '$lib/api/admin';
|
||||
import { errCode } from '$lib/api/errors';
|
||||
|
||||
const client = useQueryClient();
|
||||
|
||||
@@ -62,11 +63,11 @@
|
||||
await client.invalidateQueries({ queryKey: qk.adminUsers() });
|
||||
showToast(u.is_admin ? `${u.username} is no longer an admin.` : `${u.username} is now an admin.`);
|
||||
} catch (e: unknown) {
|
||||
const code = (e as { code?: string })?.code;
|
||||
const code = errCode(e);
|
||||
if (code === 'last_admin') {
|
||||
showToast(`Can't remove the last admin — promote someone else first.`);
|
||||
} else {
|
||||
showToast(`Action failed: ${code ?? 'unknown'}`);
|
||||
showToast(`Action failed: ${code}`);
|
||||
}
|
||||
} finally {
|
||||
saving = false;
|
||||
@@ -92,8 +93,7 @@
|
||||
createForm = { username: '', password: '', confirmPassword: '', display_name: '', is_admin: false };
|
||||
showToast('User created.');
|
||||
} catch (e: unknown) {
|
||||
const code = (e as { code?: string })?.code;
|
||||
showToast(createUserErrorMessage(code));
|
||||
showToast(createUserErrorMessage(errCode(e)));
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
@@ -117,11 +117,11 @@
|
||||
showToast(`Deleted ${confirmDeleteTarget.username}.`);
|
||||
confirmDeleteTarget = null;
|
||||
} catch (e: unknown) {
|
||||
const code = (e as { code?: string })?.code;
|
||||
const code = errCode(e);
|
||||
if (code === 'last_admin') {
|
||||
showToast(`Can't delete the last admin — promote someone else first.`);
|
||||
} else {
|
||||
showToast(`Delete failed: ${code ?? 'unknown'}`);
|
||||
showToast(`Delete failed: ${code}`);
|
||||
}
|
||||
} finally {
|
||||
saving = false;
|
||||
@@ -143,11 +143,11 @@
|
||||
resetPasswordValue = '';
|
||||
resetPasswordConfirm = '';
|
||||
} catch (e: unknown) {
|
||||
const code = (e as { code?: string })?.code;
|
||||
const code = errCode(e);
|
||||
if (code === 'password_too_short') {
|
||||
showToast('Password must be at least 8 characters.');
|
||||
} else {
|
||||
showToast(`Reset failed: ${code ?? 'unknown'}`);
|
||||
showToast(`Reset failed: ${code}`);
|
||||
}
|
||||
} finally {
|
||||
saving = false;
|
||||
@@ -163,7 +163,7 @@
|
||||
? `Auto-approve disabled for ${u.username}.`
|
||||
: `Auto-approve enabled for ${u.username}.`);
|
||||
} catch (e: unknown) {
|
||||
showToast(`Toggle failed: ${(e as { code?: string })?.code ?? 'unknown'}`);
|
||||
showToast(`Toggle failed: ${errCode(e)}`);
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
@@ -176,7 +176,7 @@
|
||||
await client.invalidateQueries({ queryKey: qk.adminInvites() });
|
||||
showToast('Invite generated. Copy the token from the list below.');
|
||||
} catch (e: unknown) {
|
||||
showToast(`Generate failed: ${(e as { code?: string })?.code ?? 'unknown'}`);
|
||||
showToast(`Generate failed: ${errCode(e)}`);
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
@@ -189,7 +189,7 @@
|
||||
await client.invalidateQueries({ queryKey: qk.adminInvites() });
|
||||
showToast('Invite revoked.');
|
||||
} catch (e: unknown) {
|
||||
showToast(`Revoke failed: ${(e as { code?: string })?.code ?? 'unknown'}`);
|
||||
showToast(`Revoke failed: ${errCode(e)}`);
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user