Skip to content

Commit

Permalink
Make VertexAIError error codes use the vertex type prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
dlarocque committed Sep 27, 2024
1 parent beaa4df commit ae29787
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
18 changes: 9 additions & 9 deletions common/api-review/vertexai-preview.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,15 +622,15 @@ export class VertexAIError extends FirebaseError {

// @public
export const enum VertexAIErrorCode {
ERROR = "error",
FETCH_ERROR = "fetch-error",
INVALID_CONTENT = "invalid-content",
NO_API_KEY = "no-api-key",
NO_MODEL = "no-model",
NO_PROJECT_ID = "no-project-id",
PARSE_FAILED = "parse-failed",
REQUEST_ERROR = "request-error",
RESPONSE_ERROR = "response-error"
ERROR = "vertexAI/error",
FETCH_ERROR = "vertexAI/fetch-error",
INVALID_CONTENT = "vertexAI/invalid-content",
NO_API_KEY = "vertexAI/no-api-key",
NO_MODEL = "vertexAI/no-model",
NO_PROJECT_ID = "vertexAI/no-project-id",
PARSE_FAILED = "vertexAI/parse-failed",
REQUEST_ERROR = "vertexAI/request-error",
RESPONSE_ERROR = "vertexAI/response-error"
}

// @public
Expand Down
7 changes: 2 additions & 5 deletions packages/vertexai/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import { FirebaseError } from '@firebase/util';
import { VertexAIErrorCode, CustomErrorData } from './types';
import { VERTEX_TYPE } from './constants';

/**
* Error class for the Vertex AI in Firebase SDK.
Expand All @@ -38,11 +37,9 @@ export class VertexAIError extends FirebaseError {
readonly customErrorData?: CustomErrorData
) {
// Match error format used by FirebaseError from ErrorFactory
const service = VERTEX_TYPE;
const serviceName = 'VertexAI';
const fullCode = `${service}/${code}`;
const fullMessage = `${serviceName}: ${message} (${fullCode}).`;
super(fullCode, fullMessage);
const fullMessage = `${serviceName}: ${message} (${code}).`;
super(code, fullMessage);

// FirebaseError initializes a stack trace, but it assumes the error is created from the error
// factory. Since we break this assumption, we set the stack trace to be originating from this
Expand Down
21 changes: 12 additions & 9 deletions packages/vertexai/src/types/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,33 @@ export interface CustomErrorData {
* @public
*/
export const enum VertexAIErrorCode {
// TODO (dlarocque): Initialize error codes using the `VERTEX_TYPE` constant
// in a computed template string literal. Can not do this until we upgrade to
// TS5: https://github.com/microsoft/TypeScript/issues/40793
/** A generic error occurred. */
ERROR = 'error',
ERROR = 'vertexAI/error',

/** An error occurred in a request. */
REQUEST_ERROR = 'request-error',
REQUEST_ERROR = 'vertexAI/request-error',

/** An error occurred in a response. */
RESPONSE_ERROR = 'response-error',
RESPONSE_ERROR = 'vertexAI/response-error',

/** An error occurred while performing a fetch. */
FETCH_ERROR = 'fetch-error',
FETCH_ERROR = 'vertexAI/fetch-error',

/** An error associated with a Content object. */
INVALID_CONTENT = 'invalid-content',
INVALID_CONTENT = 'vertexAI/invalid-content',

/** An error occurred due to a missing Firebase API key. */
NO_API_KEY = 'no-api-key',
NO_API_KEY = 'vertexAI/no-api-key',

/** An error occurred due to a model name not being specified during initialization. */
NO_MODEL = 'no-model',
NO_MODEL = 'vertexAI/no-model',

/** An error occurred due to a missing project ID. */
NO_PROJECT_ID = 'no-project-id',
NO_PROJECT_ID = 'vertexAI/no-project-id',

/** An error occurred while parsing. */
PARSE_FAILED = 'parse-failed'
PARSE_FAILED = 'vertexAI/parse-failed'
}

0 comments on commit ae29787

Please sign in to comment.