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 { 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 {
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user