From 5d1d40fa2ef418ef707aa29215594a8f22e4dadb Mon Sep 17 00:00:00 2001 From: owenofbrien <86964623+owenofbrien@users.noreply.github.com> Date: Tue, 12 Aug 2025 11:51:21 -0500 Subject: [PATCH] Fix: log api response error status codes (#6015) Co-authored-by: Gaurav <39389231+gsquared94@users.noreply.github.com> --- .../core/src/core/loggingContentGenerator.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/core/src/core/loggingContentGenerator.ts b/packages/core/src/core/loggingContentGenerator.ts index 305b19a4..13bd6918 100644 --- a/packages/core/src/core/loggingContentGenerator.ts +++ b/packages/core/src/core/loggingContentGenerator.ts @@ -28,6 +28,19 @@ import { import { ContentGenerator } from './contentGenerator.js'; import { toContents } from '../code_assist/converter.js'; +interface StructuredError { + status: number; +} + +export function isStructuredError(error: unknown): error is StructuredError { + return ( + typeof error === 'object' && + error !== null && + 'status' in error && + typeof (error as StructuredError).status === 'number' + ); +} + /** * A decorator that wraps a ContentGenerator to add logging to API calls. */ @@ -85,6 +98,9 @@ export class LoggingContentGenerator implements ContentGenerator { prompt_id, this.config.getContentGeneratorConfig()?.authType, errorType, + isStructuredError(error) + ? (error as StructuredError).status + : undefined, ), ); }