diff --git a/apps/ai-game-creator-shell/src/services/clientApi.ts b/apps/ai-game-creator-shell/src/services/clientApi.ts index e5a37c5d2..9003a8740 100644 --- a/apps/ai-game-creator-shell/src/services/clientApi.ts +++ b/apps/ai-game-creator-shell/src/services/clientApi.ts @@ -57,6 +57,16 @@ async function readApiErrorMessage(response: Response, fallback: string) { return fallback; } +function captureApiErrorStatus(url: string, response: Response) { + if (response.status < 500 && response.status !== 408) return; + void captureClientError( + new ClientAuthRequestError(`HTTP ${response.status}`, { + status: response.status, + }), + { source: 'api', action: url.split('?')[0] }, + ); +} + export async function requestClientApi( url: string, init: RequestInit, @@ -89,15 +99,7 @@ export async function requestClientApi( ); } if (!response.ok) { - const shouldCapture = response.status >= 500 || response.status === 408; - if (shouldCapture) { - void captureClientError( - new ClientAuthRequestError(`HTTP ${response.status}`, { - status: response.status, - }), - { source: 'api', action: url.split('?')[0] }, - ); - } + captureApiErrorStatus(url, response); throw new ClientAuthRequestError( await readApiErrorMessage(response, fallbackMessage), { status: response.status }, @@ -141,15 +143,7 @@ export async function requestClientApiBytes( ); } if (!response.ok) { - const shouldCapture = response.status >= 500 || response.status === 408; - if (shouldCapture) { - void captureClientError( - new ClientAuthRequestError(`HTTP ${response.status}`, { - status: response.status, - }), - { source: 'api', action: url.split('?')[0] }, - ); - } + captureApiErrorStatus(url, response); throw new ClientAuthRequestError( await readApiErrorMessage(response, fallbackMessage), { status: response.status },