Skip to content

Make VertexAIError error codes use the vertex type prefix #8542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
}
Loading