From 3b4301a3be5aebf9ff85a7e6de557ea8868dfc61 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Wed, 22 May 2024 16:27:18 -0400 Subject: [PATCH] Rename httpErrorData to customErrorData to make more future-proof --- packages/vertexai/src/errors.ts | 9 +++------ packages/vertexai/src/requests/request.test.ts | 16 ++++++++-------- packages/vertexai/src/types/error.ts | 11 ++++++++--- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/vertexai/src/errors.ts b/packages/vertexai/src/errors.ts index 7a07f05ad95..308b17d6087 100644 --- a/packages/vertexai/src/errors.ts +++ b/packages/vertexai/src/errors.ts @@ -18,8 +18,7 @@ import { FirebaseError } from '@firebase/util'; import { VertexAIErrorCode, - GenerateContentResponse, - HTTPErrorDetails + CustomErrorData } from './types'; import { VERTEX_TYPE } from './constants'; @@ -34,14 +33,12 @@ export class VertexAIError extends FirebaseError { * * @param code - The error code from {@link VertexAIErrorCode}. * @param message - A human-readable message describing the error. - * @param HTTPErrorDetails - Optional HTTP details from a bad response. - * @param generateContentResponse - Optional response from a {@link GenerateContentRequest}. + * @param customErrorData - Optional error data. */ constructor( readonly code: VertexAIErrorCode, readonly message: string, - readonly httpErrorDetails?: HTTPErrorDetails, - readonly generateContentResponse?: GenerateContentResponse + readonly customErrorData?: CustomErrorData, ) { // Match error format used by FirebaseError from ErrorFactory const service = VERTEX_TYPE; diff --git a/packages/vertexai/src/requests/request.test.ts b/packages/vertexai/src/requests/request.test.ts index ea1ce73652f..117b776dbc1 100644 --- a/packages/vertexai/src/requests/request.test.ts +++ b/packages/vertexai/src/requests/request.test.ts @@ -249,8 +249,8 @@ describe('request methods', () => { expect((e as VertexAIError).code).to.equal( VertexAIErrorCode.FETCH_ERROR ); - expect((e as VertexAIError).httpErrorDetails?.status).to.equal(500); - expect((e as VertexAIError).httpErrorDetails?.statusText).to.equal( + expect((e as VertexAIError).customErrorData?.status).to.equal(500); + expect((e as VertexAIError).customErrorData?.statusText).to.equal( 'AbortError' ); expect((e as VertexAIError).message).to.include('500 AbortError'); @@ -276,8 +276,8 @@ describe('request methods', () => { expect((e as VertexAIError).code).to.equal( VertexAIErrorCode.FETCH_ERROR ); - expect((e as VertexAIError).httpErrorDetails?.status).to.equal(500); - expect((e as VertexAIError).httpErrorDetails?.statusText).to.equal( + expect((e as VertexAIError).customErrorData?.status).to.equal(500); + expect((e as VertexAIError).customErrorData?.statusText).to.equal( 'Server Error' ); expect((e as VertexAIError).message).to.include('500 Server Error'); @@ -303,8 +303,8 @@ describe('request methods', () => { expect((e as VertexAIError).code).to.equal( VertexAIErrorCode.FETCH_ERROR ); - expect((e as VertexAIError).httpErrorDetails?.status).to.equal(500); - expect((e as VertexAIError).httpErrorDetails?.statusText).to.equal( + expect((e as VertexAIError).customErrorData?.status).to.equal(500); + expect((e as VertexAIError).customErrorData?.statusText).to.equal( 'Server Error' ); expect((e as VertexAIError).message).to.include('500 Server Error'); @@ -343,8 +343,8 @@ describe('request methods', () => { expect((e as VertexAIError).code).to.equal( VertexAIErrorCode.FETCH_ERROR ); - expect((e as VertexAIError).httpErrorDetails?.status).to.equal(500); - expect((e as VertexAIError).httpErrorDetails?.statusText).to.equal( + expect((e as VertexAIError).customErrorData?.status).to.equal(500); + expect((e as VertexAIError).customErrorData?.statusText).to.equal( 'Server Error' ); expect((e as VertexAIError).message).to.include('500 Server Error'); diff --git a/packages/vertexai/src/types/error.ts b/packages/vertexai/src/types/error.ts index b92a1a1740e..7be38b086a5 100644 --- a/packages/vertexai/src/types/error.ts +++ b/packages/vertexai/src/types/error.ts @@ -15,6 +15,8 @@ * limitations under the License. */ +import { GenerateContentResponse } from './responses'; + /** * Details object that may be included in an error response. * @@ -41,12 +43,15 @@ export interface ErrorDetails { * * @public */ -export interface HTTPErrorDetails { +export interface CustomErrorData { /** HTTP status code of the error response. */ - status: number; + status?: number; /** HTTP status text of the error response. */ - statusText: string; + statusText?: string; + + /** Response from a {@link GenerateContentRequest} */ + generateContentResponse?: GenerateContentResponse; /** Optional additional details about the error. */ errorDetails?: ErrorDetails[];