refactor(frontend): replace all as-unknown-as error casts with extractErrorCode
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 1m16s
CI / OCR Service Tests (pull_request) Successful in 20s
CI / Backend Unit Tests (pull_request) Successful in 3m27s
CI / fail2ban Regex (pull_request) Successful in 45s
CI / Semgrep Security Scan (pull_request) Successful in 19s
CI / Compose Bucket Idempotency (pull_request) Successful in 59s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-20 20:54:32 +02:00
parent d6798bc3de
commit 3f3d9a347a
25 changed files with 123 additions and 117 deletions

View File

@@ -1,6 +1,6 @@
import { error } 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 { getErrorMessage } from '$lib/shared/errors';
import type { components } from '$lib/generated/api';
@@ -34,16 +34,16 @@ export async function load({ fetch, locals }) {
]);
if (!usersResult.response.ok) {
const code = (usersResult.error as unknown as { code?: string })?.code;
throw error(usersResult.response.status, getErrorMessage(code));
throw error(usersResult.response.status, getErrorMessage(extractErrorCode(usersResult.error)));
}
if (!groupsResult.response.ok) {
const code = (groupsResult.error as unknown as { code?: string })?.code;
throw error(groupsResult.response.status, getErrorMessage(code));
throw error(
groupsResult.response.status,
getErrorMessage(extractErrorCode(groupsResult.error))
);
}
if (!tagsResult.response.ok) {
const code = (tagsResult.error as unknown as { code?: string })?.code;
throw error(tagsResult.response.status, getErrorMessage(code));
throw error(tagsResult.response.status, getErrorMessage(extractErrorCode(tagsResult.error)));
}
let inviteCount = 0;

View File

@@ -1,6 +1,6 @@
import { error, fail, redirect } from '@sveltejs/kit';
import type { PageServerLoad, Actions } from './$types';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
export const load: PageServerLoad = async ({ params, parent }) => {
@@ -24,8 +24,9 @@ export const actions: Actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { error: getErrorMessage(code) });
return fail(result.response.status, {
error: getErrorMessage(extractErrorCode(result.error))
});
}
return { success: true };
@@ -38,8 +39,9 @@ export const actions: Actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { error: getErrorMessage(code) });
return fail(result.response.status, {
error: getErrorMessage(extractErrorCode(result.error))
});
}
throw redirect(303, '/admin/groups');

View File

@@ -1,6 +1,6 @@
import { fail, redirect } from '@sveltejs/kit';
import type { Actions } from './$types';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
export const actions: Actions = {
@@ -16,8 +16,9 @@ export const actions: Actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { error: getErrorMessage(code) });
return fail(result.response.status, {
error: getErrorMessage(extractErrorCode(result.error))
});
}
throw redirect(303, '/admin/groups');

View File

@@ -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 };

View File

@@ -1,6 +1,6 @@
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
export const load: PageServerLoad = async ({ fetch }) => {
@@ -8,8 +8,7 @@ export const load: PageServerLoad = async ({ fetch }) => {
const result = await api.GET('/api/ocr/training-info');
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
throw error(result.response.status, getErrorMessage(code));
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
return { trainingInfo: result.data! };

View File

@@ -1,6 +1,6 @@
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
export const load: PageServerLoad = async ({ params, fetch }) => {
@@ -10,8 +10,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
throw error(result.response.status, getErrorMessage(code));
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
return { history: result.data!, personId: params.personId };

View File

@@ -1,6 +1,6 @@
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
export const load: PageServerLoad = async ({ fetch }) => {
@@ -8,8 +8,7 @@ export const load: PageServerLoad = async ({ fetch }) => {
const result = await api.GET('/api/ocr/training-info/global');
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
throw error(result.response.status, getErrorMessage(code));
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
return { history: result.data! };

View File

@@ -1,6 +1,6 @@
import { error, fail, redirect } from '@sveltejs/kit';
import type { PageServerLoad, Actions } from './$types';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
export const load: PageServerLoad = async ({ params, parent, url }) => {
@@ -25,8 +25,9 @@ export const actions: Actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { error: getErrorMessage(code) });
return fail(result.response.status, {
error: getErrorMessage(extractErrorCode(result.error))
});
}
return { success: true };
@@ -43,8 +44,9 @@ export const actions: Actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { error: getErrorMessage(code) });
return fail(result.response.status, {
error: getErrorMessage(extractErrorCode(result.error))
});
}
throw redirect(303, `/admin/tags/${result.data!.id}?merged=1`);
@@ -65,8 +67,9 @@ export const actions: Actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { error: getErrorMessage(code) });
return fail(result.response.status, {
error: getErrorMessage(extractErrorCode(result.error))
});
}
throw redirect(303, '/admin/tags');

View File

@@ -1,6 +1,6 @@
import { error, fail, redirect } from '@sveltejs/kit';
import type { PageServerLoad, Actions } from './$types';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
import type { components } from '$lib/generated/api';
@@ -55,8 +55,9 @@ export const actions: Actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { error: getErrorMessage(code) });
return fail(result.response.status, {
error: getErrorMessage(extractErrorCode(result.error))
});
}
return { success: true };
@@ -69,8 +70,9 @@ export const actions: Actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { error: getErrorMessage(code) });
return fail(result.response.status, {
error: getErrorMessage(extractErrorCode(result.error))
});
}
throw redirect(303, '/admin/users');

View File

@@ -1,6 +1,6 @@
import { error, fail, redirect } from '@sveltejs/kit';
import type { PageServerLoad, Actions } from './$types';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
export const load: PageServerLoad = async ({ fetch, locals }) => {
@@ -35,8 +35,9 @@ export const actions: Actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { error: getErrorMessage(code) });
return fail(result.response.status, {
error: getErrorMessage(extractErrorCode(result.error))
});
}
throw redirect(303, '/admin/users');

View File

@@ -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 { components, operations } from '$lib/generated/api';
@@ -79,8 +79,9 @@ export const actions = {
params: { path: { id: notificationId } }
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { error: getErrorMessage(code) });
return fail(result.response.status, {
error: getErrorMessage(extractErrorCode(result.error))
});
}
return { success: true };
},
@@ -89,8 +90,9 @@ export const actions = {
const api = createApiClient(fetch);
const result = await api.POST('/api/notifications/read-all');
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { error: getErrorMessage(code) });
return fail(result.response.status, {
error: getErrorMessage(extractErrorCode(result.error))
});
}
return { success: true };
}

View File

@@ -1,6 +1,6 @@
import { error } from '@sveltejs/kit';
import type { components } from '$lib/generated/api';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
export async function load({ url, fetch, locals }) {
@@ -39,8 +39,7 @@ export async function load({ url, fetch, locals }) {
})
.then((result) => {
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
throw error(result.response.status, getErrorMessage(code));
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
documents = result.data ?? [];
})
@@ -49,8 +48,7 @@ export async function load({ url, fetch, locals }) {
requests.push(
api.GET('/api/persons/{id}', { params: { path: { id: senderId } } }).then((result) => {
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
throw error(result.response.status, getErrorMessage(code));
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
const p = result.data as { displayName: string } | undefined;
if (p) senderName = p.displayName;
@@ -62,8 +60,7 @@ export async function load({ url, fetch, locals }) {
requests.push(
api.GET('/api/persons/{id}', { params: { path: { id: receiverId } } }).then((result) => {
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
throw error(result.response.status, getErrorMessage(code));
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
const p = result.data as { displayName: string } | undefined;
if (p) receiverName = p.displayName;

View File

@@ -1,5 +1,5 @@
import { redirect } 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 { components } from '$lib/generated/api';
@@ -103,8 +103,7 @@ export async function load({ url, fetch }) {
}
const errorMessage: string | null = !result.response.ok
? (getErrorMessage((result.error as unknown as { code?: string })?.code) ??
'Daten konnten nicht geladen werden.')
? (getErrorMessage(extractErrorCode(result.error)) ?? 'Daten konnten nicht geladen werden.')
: null;
return {

View File

@@ -1,5 +1,5 @@
import { error, redirect } 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 { inferredRelationshipLabel } from '$lib/person/relationshipLabels';
@@ -17,8 +17,7 @@ export async function load({ params, fetch }) {
if (docResult.response.status === 401) throw redirect(302, '/login');
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)));
}
const document = docResult.data!;

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!;

View File

@@ -1,6 +1,6 @@
import { error, 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 { getErrorMessage, parseBackendError } from '$lib/shared/errors';
export async function load({
@@ -31,8 +31,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)));
}
const incompleteCount = countResult.response.ok ? (countResult.data?.count ?? 0) : 0;

View File

@@ -1,5 +1,5 @@
import { error } 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 { components } from '$lib/generated/api';
import type { PageServerLoad } from './$types';
@@ -25,8 +25,7 @@ export const load: PageServerLoad = async ({ url, fetch }) => {
]);
if (!listResult.response.ok) {
const code = (listResult.error as unknown as { code?: string })?.code;
throw error(listResult.response.status, getErrorMessage(code));
throw error(listResult.response.status, getErrorMessage(extractErrorCode(listResult.error)));
}
const personFilters = personResults

View File

@@ -1,5 +1,5 @@
import { error } 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 { PageServerLoad } from './$types';
@@ -9,8 +9,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
params: { path: { id: params.id } }
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
throw error(result.response.status, getErrorMessage(code));
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
return { geschichte: result.data! };
};

View File

@@ -1,5 +1,5 @@
import { error, redirect } 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 { PageServerLoad } from './$types';
@@ -13,8 +13,7 @@ export const load: PageServerLoad = async ({ params, fetch, parent }) => {
params: { path: { id: params.id } }
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
throw error(result.response.status, getErrorMessage(code));
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
return { geschichte: result.data! };
};

View File

@@ -1,5 +1,5 @@
import { error } from '@sveltejs/kit';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
export async function load({ params, fetch, locals }) {
@@ -32,8 +32,10 @@ export async function load({ params, fetch, locals }) {
]);
if (!personResult.response.ok) {
const code = (personResult.error as unknown as { code?: string })?.code;
throw error(personResult.response.status, getErrorMessage(code));
throw error(
personResult.response.status,
getErrorMessage(extractErrorCode(personResult.error))
);
}
return {

View File

@@ -1,5 +1,5 @@
import { error, fail, redirect } 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 {
normalizePersonType,
@@ -25,8 +25,7 @@ export async function load({ params, fetch, locals }) {
]);
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
throw error(result.response.status, getErrorMessage(code));
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
const person = result.data!;
@@ -74,8 +73,9 @@ export const actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { updateError: getErrorMessage(code) });
return fail(result.response.status, {
updateError: getErrorMessage(extractErrorCode(result.error))
});
}
throw redirect(303, `/persons/${params.id}`);
@@ -100,8 +100,9 @@ export const actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { mergeError: getErrorMessage(code) });
return fail(result.response.status, {
mergeError: getErrorMessage(extractErrorCode(result.error))
});
}
throw redirect(303, `/persons/${targetPersonId}`);
@@ -127,8 +128,9 @@ export const actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { aliasError: getErrorMessage(code) });
return fail(result.response.status, {
aliasError: getErrorMessage(extractErrorCode(result.error))
});
}
return { aliasSuccess: true };
@@ -148,8 +150,9 @@ export const actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { aliasError: getErrorMessage(code) });
return fail(result.response.status, {
aliasError: getErrorMessage(extractErrorCode(result.error))
});
}
return { aliasSuccess: true };
@@ -166,8 +169,9 @@ export const actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { relationshipError: getErrorMessage(code) });
return fail(result.response.status, {
relationshipError: getErrorMessage(extractErrorCode(result.error))
});
}
return { relationshipSuccess: true };
},
@@ -211,8 +215,9 @@ export const actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { relationshipError: getErrorMessage(code) });
return fail(result.response.status, {
relationshipError: getErrorMessage(extractErrorCode(result.error))
});
}
return { relationshipSuccess: true };
},
@@ -230,8 +235,9 @@ export const actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { relationshipError: getErrorMessage(code) });
return fail(result.response.status, {
relationshipError: getErrorMessage(extractErrorCode(result.error))
});
}
return { relationshipSuccess: true };
}

View File

@@ -1,5 +1,5 @@
import { error, fail, redirect } 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 {
normalizePersonType,
@@ -57,9 +57,8 @@ export const actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, {
error: getErrorMessage(code),
error: getErrorMessage(extractErrorCode(result.error)),
personType,
title,
firstName,

View File

@@ -1,7 +1,7 @@
import { fail } from '@sveltejs/kit';
import { env } from '$env/dynamic/private';
import type { PageServerLoad, Actions } from './$types';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
const apiBase = () => env.API_INTERNAL_URL || 'http://localhost:8080';
@@ -27,8 +27,9 @@ export const actions: Actions = {
const result = await api.PUT('/api/users/me', { body });
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { updateError: getErrorMessage(code) });
return fail(result.response.status, {
updateError: getErrorMessage(extractErrorCode(result.error))
});
}
return { updateSuccess: true };
@@ -50,8 +51,9 @@ export const actions: Actions = {
});
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
return fail(result.response.status, { passwordError: getErrorMessage(code) });
return fail(result.response.status, {
passwordError: getErrorMessage(extractErrorCode(result.error))
});
}
return { passwordSuccess: true };

View File

@@ -1,5 +1,5 @@
import { error, redirect } from '@sveltejs/kit';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
export async function load({ fetch }) {
@@ -9,8 +9,7 @@ export async function load({ fetch }) {
if (result.response.status === 401) throw redirect(302, '/login');
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
throw error(result.response.status, getErrorMessage(code));
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
const network = result.data!;

View File

@@ -1,6 +1,6 @@
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { createApiClient } from '$lib/shared/api.server';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
export const load: PageServerLoad = async ({ params, fetch }) => {
@@ -8,8 +8,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
const result = await api.GET('/api/users/{id}', { params: { path: { id: params.id } } });
if (!result.response.ok) {
const code = (result.error as unknown as { code?: string })?.code;
throw error(result.response.status, getErrorMessage(code));
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
return { profileUser: result.data! };