From f9d92e6cc9d50228a581bbb338208dc629bbe8b4 Mon Sep 17 00:00:00 2001 From: Chaos Date: Mon, 24 Nov 2025 17:26:37 +0800 Subject: [PATCH] fix(auth): handle API error types correctly in login action - Introduce ApiError interface for better type safety - Replace generic HttpError handling with specific ApiError casting - Remove unnecessary console log in error handling block - Ensure error details are properly extracted and returned to client --- src/lib/types/error.ts | 8 ++++++++ src/routes/auth/login/+page.server.ts | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 src/lib/types/error.ts diff --git a/src/lib/types/error.ts b/src/lib/types/error.ts new file mode 100644 index 0000000..e56081a --- /dev/null +++ b/src/lib/types/error.ts @@ -0,0 +1,8 @@ +export interface ApiError { + status: number; + details: { + code: number; + msg: string; + }; + name: string; +} \ No newline at end of file diff --git a/src/routes/auth/login/+page.server.ts b/src/routes/auth/login/+page.server.ts index 2b253dd..9325408 100644 --- a/src/routes/auth/login/+page.server.ts +++ b/src/routes/auth/login/+page.server.ts @@ -2,6 +2,7 @@ import type { Actions } from './$types'; import { fail } from '@sveltejs/kit'; import { authService } from '$lib/api/services/authService.ts'; import { HttpError } from '$lib/api/httpClient.ts'; +import type { ApiError } from '$lib/types/error.ts'; export const actions:Actions = { @@ -30,8 +31,8 @@ export const actions:Actions = { return {success:true}; }catch ( error){ if (error instanceof HttpError){ - console.log(JSON.stringify(error)); - return fail(400, {message:error.details.msg}); + const apiError = error as unknown as ApiError; + return fail(400, {message:apiError.details.msg}); } }