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:
Marcel
2026-05-20 20:54:32 +02:00
committed by marcel
parent 1a7e4ce536
commit 2914010b68
24 changed files with 116 additions and 112 deletions

View File

@@ -1,6 +1,6 @@
import { error, fail, redirect } from '@sveltejs/kit';
import { env } from '$env/dynamic/private';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { parseBackendError, getErrorMessage } from '$lib/shared/errors';
export async function load({
@@ -30,8 +30,7 @@ export async function load({
]);
if (!docResult.response.ok) {
const code = (docResult.error as unknown as { code?: string })?.code;
throw error(docResult.response.status, getErrorMessage(code));
throw error(docResult.response.status, getErrorMessage(extractErrorCode(docResult.error)));
}
if (!personsResult.response.ok) {
throw error(personsResult.response.status, getErrorMessage('INTERNAL_ERROR'));
@@ -76,8 +75,9 @@ export const actions = {
// Fetch current document to preserve all existing fields
const docResult = await api.GET('/api/documents/{id}', { params: { path: { id: params.id } } });
if (!docResult.response.ok) {
const code = (docResult.error as unknown as { code?: string })?.code;
return fail(docResult.response.status, { error: getErrorMessage(code) });
return fail(docResult.response.status, {
error: getErrorMessage(extractErrorCode(docResult.error))
});
}
const doc = docResult.data!;