From cbdd7becbfd266813b7403015acdac6df2b566c2 Mon Sep 17 00:00:00 2001 From: "genkit-factory-dev[bot]" <5414006+genkit-factory-dev[bot]@users.noreply.github.com> Date: Wed, 21 Oct 2026 17:38:29 -0400 Subject: [PATCH] fix(js/google-genai): log failed requests at debug level before rethrowing Requested-by: Samuel Bushi --- .../google-genai/src/googleai/client.ts | 2 +- .../google-genai/src/vertexai/client.ts | 2 +- .../tests/googleai/client_test.ts | 21 +++++++++++++++++++ .../tests/vertexai/client_test.ts | 21 +++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/js/plugins/google-genai/src/googleai/client.ts b/js/plugins/google-genai/src/googleai/client.ts index 363a60321f..138a9f549d 100644 --- a/js/plugins/google-genai/src/googleai/client.ts +++ b/js/plugins/google-genai/src/googleai/client.ts @@ -629,7 +629,7 @@ async function makeRequest( } return response; } catch (e: unknown) { - logger.error(e); + logger.debug(e); if (e instanceof GenkitError) { throw e; } diff --git a/js/plugins/google-genai/src/vertexai/client.ts b/js/plugins/google-genai/src/vertexai/client.ts index 41aae80e29..e25c896540 100644 --- a/js/plugins/google-genai/src/vertexai/client.ts +++ b/js/plugins/google-genai/src/vertexai/client.ts @@ -543,7 +543,7 @@ async function makeRequest( } return response; } catch (e: unknown) { - logger.error(e); + logger.debug(e); if (e instanceof GenkitError) { throw e; } diff --git a/js/plugins/google-genai/tests/googleai/client_test.ts b/js/plugins/google-genai/tests/googleai/client_test.ts index 8defc13153..5824bcc2cd 100644 --- a/js/plugins/google-genai/tests/googleai/client_test.ts +++ b/js/plugins/google-genai/tests/googleai/client_test.ts @@ -15,6 +15,7 @@ */ import * as assert from 'assert'; +import { logger } from 'genkit/logging'; import { afterEach, beforeEach, describe, it } from 'node:test'; import * as sinon from 'sinon'; import { TextEncoder } from 'util'; @@ -273,6 +274,26 @@ describe('Google AI Client', () => { ); }); + it('should log failed requests at debug level and not error level before rethrowing', async () => { + const errorStub = sinon.stub(logger, 'error'); + const debugStub = sinon.stub(logger, 'debug'); + mockFetchResponse( + { error: { message: 'Too many requests' } }, + false, + 429, + 'Too Many Requests' + ); + + await assert.rejects(listModels(apiKey), (err: any) => { + assert.strictEqual(err.name, 'GenkitError'); + assert.strictEqual(err.status, 'RESOURCE_EXHAUSTED'); + return true; + }); + + sinon.assert.notCalled(errorStub); + sinon.assert.calledOnce(debugStub); + }); + it('does not apply Interactions error-code mapping to non-Interactions URLs', async () => { // `safety` would map to FAILED_PRECONDITION on the Interactions path. mockFetchResponse( diff --git a/js/plugins/google-genai/tests/vertexai/client_test.ts b/js/plugins/google-genai/tests/vertexai/client_test.ts index 0eca5effb9..cf9c3d6863 100644 --- a/js/plugins/google-genai/tests/vertexai/client_test.ts +++ b/js/plugins/google-genai/tests/vertexai/client_test.ts @@ -15,6 +15,7 @@ */ import * as assert from 'assert'; +import { logger } from 'genkit/logging'; import { GoogleAuth } from 'google-auth-library'; import { afterEach, beforeEach, describe, it } from 'node:test'; import * as sinon from 'sinon'; @@ -1137,6 +1138,26 @@ describe('Vertex AI Client', () => { return true; }); }); + + it('should log failed requests at debug level and not error level before rethrowing', async () => { + const errorStub = sinon.stub(logger, 'error'); + const debugStub = sinon.stub(logger, 'debug'); + mockFetchResponse( + { error: { message: 'Too many requests' } }, + false, + 429, + 'Too Many Requests' + ); + + await assert.rejects(listModels(regionalClientOptions), (err: any) => { + assert.strictEqual(err.name, 'GenkitError'); + assert.strictEqual(err.status, 'RESOURCE_EXHAUSTED'); + return true; + }); + + sinon.assert.notCalled(errorStub); + sinon.assert.calledOnce(debugStub); + }); }); describe('generateContentStream full aggregation tests', () => {