From 64d54ed3e295bb96b1cab8295f0bfb77b6fb73c6 Mon Sep 17 00:00:00 2001 From: Haileyesus <118998054+blackmammoth@users.noreply.github.com> Date: Sat, 18 Apr 2026 13:28:20 +0300 Subject: [PATCH] refactor(auth): standardize API response structure and remove unused error handling --- server/modules/providers/provider.routes.ts | 2 +- server/shared/types.ts | 9 --------- server/shared/utils.ts | 16 ---------------- .../provider-auth/hooks/useProviderAuthStatus.ts | 9 +++++++-- 4 files changed, 8 insertions(+), 28 deletions(-) diff --git a/server/modules/providers/provider.routes.ts b/server/modules/providers/provider.routes.ts index 5419f3d4..895aba84 100644 --- a/server/modules/providers/provider.routes.ts +++ b/server/modules/providers/provider.routes.ts @@ -148,7 +148,7 @@ router.get( asyncHandler(async (req: Request, res: Response) => { const provider = parseProvider(req.params.provider); const status = await providerAuthService.getProviderAuthStatus(provider); - res.json(status); + res.json(createApiSuccessResponse(status)); }), ); diff --git a/server/shared/types.ts b/server/shared/types.ts index 86de0f71..21933420 100644 --- a/server/shared/types.ts +++ b/server/shared/types.ts @@ -5,15 +5,6 @@ export type ApiSuccessShape = { data: TData; }; -export type ApiErrorShape = { - success: false; - error: { - code: string; - message: string; - details?: unknown; - }; -}; - // --------------------------------------------------------------------------------------------- export type LLMProvider = 'claude' | 'codex' | 'gemini' | 'cursor'; diff --git a/server/shared/utils.ts b/server/shared/utils.ts index 60eea254..40fbe64a 100644 --- a/server/shared/utils.ts +++ b/server/shared/utils.ts @@ -6,7 +6,6 @@ import path from 'node:path'; import type { NextFunction, Request, RequestHandler, Response } from 'express'; import type { - ApiErrorShape, ApiSuccessShape, AppErrorOptions, NormalizedMessage, @@ -30,21 +29,6 @@ export function createApiSuccessResponse( }; } -export function createApiErrorResponse( - code: string, - message: string, - details?: unknown -): ApiErrorShape { - return { - success: false, - error: { - code, - message, - details, - } - }; -} - export function asyncHandler( handler: (req: Request, res: Response, next: NextFunction) => Promise ): RequestHandler { diff --git a/src/components/provider-auth/hooks/useProviderAuthStatus.ts b/src/components/provider-auth/hooks/useProviderAuthStatus.ts index 1f988820..387d6327 100644 --- a/src/components/provider-auth/hooks/useProviderAuthStatus.ts +++ b/src/components/provider-auth/hooks/useProviderAuthStatus.ts @@ -18,6 +18,11 @@ type ProviderAuthStatusPayload = { error?: string | null; }; +type ProviderAuthStatusApiResponse = { + success: boolean; + data: ProviderAuthStatusPayload; +}; + const FALLBACK_STATUS_ERROR = 'Failed to check authentication status'; const FALLBACK_UNKNOWN_ERROR = 'Unknown error'; @@ -82,8 +87,8 @@ export function useProviderAuthStatus( return; } - const payload = (await response.json()) as ProviderAuthStatusPayload; - setProviderStatus(provider, toProviderAuthStatus(payload)); + const payload = (await response.json()) as ProviderAuthStatusApiResponse; + setProviderStatus(provider, toProviderAuthStatus(payload.data)); } catch (caughtError) { console.error(`Error checking ${provider} auth status:`, caughtError); setProviderStatus(provider, {