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