Skip to content

Commit

Permalink
Rename httpErrorData to customErrorData to make more future-proof
Browse files Browse the repository at this point in the history
  • Loading branch information
dlarocque committed May 23, 2024
1 parent c01003c commit 3b4301a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
9 changes: 3 additions & 6 deletions packages/vertexai/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import { FirebaseError } from '@firebase/util';
import {
VertexAIErrorCode,
GenerateContentResponse,
HTTPErrorDetails
CustomErrorData
} from './types';
import { VERTEX_TYPE } from './constants';

Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions packages/vertexai/src/requests/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
11 changes: 8 additions & 3 deletions packages/vertexai/src/types/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import { GenerateContentResponse } from './responses';

/**
* Details object that may be included in an error response.
*
Expand All @@ -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[];
Expand Down

0 comments on commit 3b4301a

Please sign in to comment.