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
This commit is contained in:
Chaos
2025-11-24 17:26:37 +08:00
parent d4ace86fb3
commit f9d92e6cc9
2 changed files with 11 additions and 2 deletions

8
src/lib/types/error.ts Normal file
View File

@@ -0,0 +1,8 @@
export interface ApiError {
status: number;
details: {
code: number;
msg: string;
};
name: string;
}

View File

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