mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-01 09:55:34 +08:00
refactor(auth): standardize API response structure and remove unused error handling
This commit is contained in:
@@ -148,7 +148,7 @@ router.get(
|
|||||||
asyncHandler(async (req: Request, res: Response) => {
|
asyncHandler(async (req: Request, res: Response) => {
|
||||||
const provider = parseProvider(req.params.provider);
|
const provider = parseProvider(req.params.provider);
|
||||||
const status = await providerAuthService.getProviderAuthStatus(provider);
|
const status = await providerAuthService.getProviderAuthStatus(provider);
|
||||||
res.json(status);
|
res.json(createApiSuccessResponse(status));
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,6 @@ export type ApiSuccessShape<TData = unknown> = {
|
|||||||
data: TData;
|
data: TData;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ApiErrorShape = {
|
|
||||||
success: false;
|
|
||||||
error: {
|
|
||||||
code: string;
|
|
||||||
message: string;
|
|
||||||
details?: unknown;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
export type LLMProvider = 'claude' | 'codex' | 'gemini' | 'cursor';
|
export type LLMProvider = 'claude' | 'codex' | 'gemini' | 'cursor';
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import path from 'node:path';
|
|||||||
import type { NextFunction, Request, RequestHandler, Response } from 'express';
|
import type { NextFunction, Request, RequestHandler, Response } from 'express';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ApiErrorShape,
|
|
||||||
ApiSuccessShape,
|
ApiSuccessShape,
|
||||||
AppErrorOptions,
|
AppErrorOptions,
|
||||||
NormalizedMessage,
|
NormalizedMessage,
|
||||||
@@ -30,21 +29,6 @@ export function createApiSuccessResponse<TData>(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createApiErrorResponse(
|
|
||||||
code: string,
|
|
||||||
message: string,
|
|
||||||
details?: unknown
|
|
||||||
): ApiErrorShape {
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
error: {
|
|
||||||
code,
|
|
||||||
message,
|
|
||||||
details,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function asyncHandler(
|
export function asyncHandler(
|
||||||
handler: (req: Request, res: Response, next: NextFunction) => Promise<unknown>
|
handler: (req: Request, res: Response, next: NextFunction) => Promise<unknown>
|
||||||
): RequestHandler {
|
): RequestHandler {
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ type ProviderAuthStatusPayload = {
|
|||||||
error?: string | null;
|
error?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ProviderAuthStatusApiResponse = {
|
||||||
|
success: boolean;
|
||||||
|
data: ProviderAuthStatusPayload;
|
||||||
|
};
|
||||||
|
|
||||||
const FALLBACK_STATUS_ERROR = 'Failed to check authentication status';
|
const FALLBACK_STATUS_ERROR = 'Failed to check authentication status';
|
||||||
const FALLBACK_UNKNOWN_ERROR = 'Unknown error';
|
const FALLBACK_UNKNOWN_ERROR = 'Unknown error';
|
||||||
|
|
||||||
@@ -82,8 +87,8 @@ export function useProviderAuthStatus(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = (await response.json()) as ProviderAuthStatusPayload;
|
const payload = (await response.json()) as ProviderAuthStatusApiResponse;
|
||||||
setProviderStatus(provider, toProviderAuthStatus(payload));
|
setProviderStatus(provider, toProviderAuthStatus(payload.data));
|
||||||
} catch (caughtError) {
|
} catch (caughtError) {
|
||||||
console.error(`Error checking ${provider} auth status:`, caughtError);
|
console.error(`Error checking ${provider} auth status:`, caughtError);
|
||||||
setProviderStatus(provider, {
|
setProviderStatus(provider, {
|
||||||
|
|||||||
Reference in New Issue
Block a user