Skip to content

Commit ae29787

Browse files
committed
Make VertexAIError error codes use the vertex type prefix
1 parent beaa4df commit ae29787

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

common/api-review/vertexai-preview.api.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -622,15 +622,15 @@ export class VertexAIError extends FirebaseError {
622622

623623
// @public
624624
export const enum VertexAIErrorCode {
625-
ERROR = "error",
626-
FETCH_ERROR = "fetch-error",
627-
INVALID_CONTENT = "invalid-content",
628-
NO_API_KEY = "no-api-key",
629-
NO_MODEL = "no-model",
630-
NO_PROJECT_ID = "no-project-id",
631-
PARSE_FAILED = "parse-failed",
632-
REQUEST_ERROR = "request-error",
633-
RESPONSE_ERROR = "response-error"
625+
ERROR = "vertexAI/error",
626+
FETCH_ERROR = "vertexAI/fetch-error",
627+
INVALID_CONTENT = "vertexAI/invalid-content",
628+
NO_API_KEY = "vertexAI/no-api-key",
629+
NO_MODEL = "vertexAI/no-model",
630+
NO_PROJECT_ID = "vertexAI/no-project-id",
631+
PARSE_FAILED = "vertexAI/parse-failed",
632+
REQUEST_ERROR = "vertexAI/request-error",
633+
RESPONSE_ERROR = "vertexAI/response-error"
634634
}
635635

636636
// @public

packages/vertexai/src/errors.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import { FirebaseError } from '@firebase/util';
1919
import { VertexAIErrorCode, CustomErrorData } from './types';
20-
import { VERTEX_TYPE } from './constants';
2120

2221
/**
2322
* Error class for the Vertex AI in Firebase SDK.
@@ -38,11 +37,9 @@ export class VertexAIError extends FirebaseError {
3837
readonly customErrorData?: CustomErrorData
3938
) {
4039
// Match error format used by FirebaseError from ErrorFactory
41-
const service = VERTEX_TYPE;
4240
const serviceName = 'VertexAI';
43-
const fullCode = `${service}/${code}`;
44-
const fullMessage = `${serviceName}: ${message} (${fullCode}).`;
45-
super(fullCode, fullMessage);
41+
const fullMessage = `${serviceName}: ${message} (${code}).`;
42+
super(code, fullMessage);
4643

4744
// FirebaseError initializes a stack trace, but it assumes the error is created from the error
4845
// factory. Since we break this assumption, we set the stack trace to be originating from this

packages/vertexai/src/types/error.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,33 @@ export interface CustomErrorData {
6363
* @public
6464
*/
6565
export const enum VertexAIErrorCode {
66+
// TODO (dlarocque): Initialize error codes using the `VERTEX_TYPE` constant
67+
// in a computed template string literal. Can not do this until we upgrade to
68+
// TS5: https://github.com/microsoft/TypeScript/issues/40793
6669
/** A generic error occurred. */
67-
ERROR = 'error',
70+
ERROR = 'vertexAI/error',
6871

6972
/** An error occurred in a request. */
70-
REQUEST_ERROR = 'request-error',
73+
REQUEST_ERROR = 'vertexAI/request-error',
7174

7275
/** An error occurred in a response. */
73-
RESPONSE_ERROR = 'response-error',
76+
RESPONSE_ERROR = 'vertexAI/response-error',
7477

7578
/** An error occurred while performing a fetch. */
76-
FETCH_ERROR = 'fetch-error',
79+
FETCH_ERROR = 'vertexAI/fetch-error',
7780

7881
/** An error associated with a Content object. */
79-
INVALID_CONTENT = 'invalid-content',
82+
INVALID_CONTENT = 'vertexAI/invalid-content',
8083

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

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

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

9093
/** An error occurred while parsing. */
91-
PARSE_FAILED = 'parse-failed'
94+
PARSE_FAILED = 'vertexAI/parse-failed'
9295
}

0 commit comments

Comments
 (0)