refactor(frontend): replace all as-unknown-as error casts with extractErrorCode
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { fail } from '@sveltejs/kit';
|
||||
import { createApiClient } from '$lib/shared/api.server';
|
||||
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
|
||||
import { getErrorMessage } from '$lib/shared/errors';
|
||||
import type { Actions, PageServerLoad } from './$types';
|
||||
import type { components } from '$lib/generated/api';
|
||||
@@ -25,8 +25,7 @@ export const load: PageServerLoad = async ({ url, fetch }) => {
|
||||
let invites: InviteListItem[] = [];
|
||||
let loadError: string | null = null;
|
||||
if (!invitesResult.response.ok) {
|
||||
const code = (invitesResult.error as unknown as { code?: string })?.code;
|
||||
loadError = code ?? 'INTERNAL_ERROR';
|
||||
loadError = extractErrorCode(invitesResult.error) ?? 'INTERNAL_ERROR';
|
||||
} else {
|
||||
invites = (invitesResult.data ?? []) as InviteListItem[];
|
||||
}
|
||||
@@ -34,8 +33,7 @@ export const load: PageServerLoad = async ({ url, fetch }) => {
|
||||
let groups: UserGroup[] = [];
|
||||
let groupsLoadError: string | null = null;
|
||||
if (!groupsResult.response.ok) {
|
||||
const code = (groupsResult.error as unknown as { code?: string })?.code;
|
||||
groupsLoadError = code ?? 'INTERNAL_ERROR';
|
||||
groupsLoadError = extractErrorCode(groupsResult.error) ?? 'INTERNAL_ERROR';
|
||||
} else {
|
||||
const raw = groupsResult.data ?? [];
|
||||
groups = [...raw].sort((a, b) => a.name.localeCompare(b.name));
|
||||
@@ -62,8 +60,9 @@ export const actions = {
|
||||
});
|
||||
|
||||
if (!result.response.ok) {
|
||||
const code = (result.error as unknown as { code?: string })?.code;
|
||||
return fail(result.response.status, { createError: code ?? 'INTERNAL_ERROR' });
|
||||
return fail(result.response.status, {
|
||||
createError: extractErrorCode(result.error) ?? 'INTERNAL_ERROR'
|
||||
});
|
||||
}
|
||||
|
||||
return { created: result.data! as InviteListItem };
|
||||
@@ -78,8 +77,9 @@ export const actions = {
|
||||
const result = await api.DELETE('/api/invites/{id}', { params: { path: { id } } });
|
||||
|
||||
if (!result.response.ok) {
|
||||
const code = (result.error as unknown as { code?: string })?.code;
|
||||
return fail(result.response.status, { revokeError: code ?? 'INTERNAL_ERROR' });
|
||||
return fail(result.response.status, {
|
||||
revokeError: extractErrorCode(result.error) ?? 'INTERNAL_ERROR'
|
||||
});
|
||||
}
|
||||
|
||||
return { revoked: id };
|
||||
|
||||
Reference in New Issue
Block a user