Skip to content

Commit b57febe

Browse files
committed
fix error class
1 parent e4beaf5 commit b57febe

File tree

5 files changed

+24
-29
lines changed

5 files changed

+24
-29
lines changed

packages/vertexai/src/api.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ describe('Top level API', () => {
3939
getGenerativeModel(fakeVertexAI, {} as ModelParams);
4040
} catch (e) {
4141
expect((e as VertexAIError).code).includes(VertexAIErrorCode.NO_MODEL);
42-
expect((e as VertexAIError).message).equals(
43-
`Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })`
42+
expect((e as VertexAIError).message).includes(
43+
`VertexAI: Must provide a model name. Example: ` +
44+
`getGenerativeModel({ model: 'my-model-name' }) (vertexAI/${VertexAIErrorCode.NO_MODEL})`
4445
);
4546
}
4647
});
@@ -54,7 +55,9 @@ describe('Top level API', () => {
5455
} catch (e) {
5556
expect((e as VertexAIError).code).includes(VertexAIErrorCode.NO_API_KEY);
5657
expect((e as VertexAIError).message).equals(
57-
`The "apiKey" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid API key.`
58+
`VertexAI: The "apiKey" field is empty in the local ` +
59+
`Firebase config. Firebase VertexAI requires this field to` +
60+
` contain a valid API key. (vertexAI/${VertexAIErrorCode.NO_API_KEY})`
5861
);
5962
}
6063
});
@@ -70,7 +73,9 @@ describe('Top level API', () => {
7073
VertexAIErrorCode.NO_PROJECT_ID
7174
);
7275
expect((e as VertexAIError).message).equals(
73-
`The "projectId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid project ID.`
76+
`VertexAI: The "projectId" field is empty in the local` +
77+
` Firebase config. Firebase VertexAI requires this field ` +
78+
`to contain a valid project ID. (vertexAI/${VertexAIErrorCode.NO_PROJECT_ID})`
7479
);
7580
}
7681
});

packages/vertexai/src/errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ export class VertexAIError extends FirebaseError {
3333
* @param customErrorData - Optional error data.
3434
*/
3535
constructor(
36-
code: VertexAIErrorCode,
36+
readonly code: VertexAIErrorCode,
3737
message: string,
3838
readonly customErrorData?: CustomErrorData
3939
) {
4040
// Match error format used by FirebaseError from ErrorFactory
4141
const service = VERTEX_TYPE;
4242
const serviceName = 'VertexAI';
4343
const fullCode = `${service}/${code}`;
44-
const fullMessage = `${serviceName}: ${message} (${fullCode}).`;
45-
super(fullCode, fullMessage);
44+
const fullMessage = `${serviceName}: ${message} (${fullCode})`;
45+
super(code, fullMessage);
4646

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

packages/vertexai/src/requests/schema-builder.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { VertexAIErrorCode } from '../types';
2222

2323
use(sinonChai);
2424

25-
describe.only('Schema builder', () => {
25+
describe('Schema builder', () => {
2626
it('builds integer schema', () => {
2727
const schema = Schema.integer();
2828
expect(schema.toJSON()).to.eql({

packages/vertexai/src/requests/schema-builder.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
SchemaInterface,
55
SchemaType,
66
SchemaParams,
7-
_SchemaRequest,
7+
SchemaRequest,
88
ObjectSchemaInterface
99
} from '../types/schema';
1010

@@ -56,7 +56,7 @@ export abstract class Schema implements SchemaInterface {
5656
* Defines how this Schema should be serialized as JSON.
5757
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior
5858
*/
59-
toJSON(): _SchemaRequest {
59+
toJSON(): SchemaRequest {
6060
const obj: { type: SchemaType; [key: string]: unknown } = {
6161
type: this.type
6262
};
@@ -67,7 +67,7 @@ export abstract class Schema implements SchemaInterface {
6767
}
6868
}
6969
}
70-
return obj as _SchemaRequest;
70+
return obj as SchemaRequest;
7171
}
7272

7373
static array(arrayParams: SchemaParams & { items: Schema }): ArraySchema {
@@ -181,15 +181,12 @@ export class StringSchema extends Schema {
181181
this.enum = enumValues;
182182
}
183183

184-
/**
185-
* @internal
186-
*/
187-
toJSON(): _SchemaRequest {
184+
toJSON(): SchemaRequest {
188185
const obj = super.toJSON();
189186
if (this.enum) {
190187
obj['enum'] = this.enum;
191188
}
192-
return obj as _SchemaRequest;
189+
return obj as SchemaRequest;
193190
}
194191
}
195192

@@ -207,10 +204,7 @@ export class ArraySchema extends Schema {
207204
});
208205
}
209206

210-
/**
211-
* @internal
212-
*/
213-
toJSON(): _SchemaRequest {
207+
toJSON(): SchemaRequest {
214208
const obj = super.toJSON();
215209
obj.items = this.items.toJSON();
216210
return obj;
@@ -236,10 +230,7 @@ export class ObjectSchema extends Schema {
236230
});
237231
}
238232

239-
/**
240-
* @internal
241-
*/
242-
toJSON(): _SchemaRequest {
233+
toJSON(): SchemaRequest {
243234
const obj = super.toJSON();
244235
obj.properties = { ...this.properties };
245236
const required = [];
@@ -257,7 +248,7 @@ export class ObjectSchema extends Schema {
257248
if (this.properties.hasOwnProperty(propertyKey)) {
258249
obj.properties[propertyKey] = this.properties[
259250
propertyKey
260-
].toJSON() as _SchemaRequest;
251+
].toJSON() as SchemaRequest;
261252
if (!this.optionalProperties.includes(propertyKey)) {
262253
required.push(propertyKey);
263254
}
@@ -267,6 +258,6 @@ export class ObjectSchema extends Schema {
267258
obj.required = required;
268259
}
269260
delete (obj as ObjectSchemaInterface).optionalProperties;
270-
return obj as _SchemaRequest;
261+
return obj as SchemaRequest;
271262
}
272263
}

packages/vertexai/src/types/schema.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ export interface SchemaParams extends SchemaShared<SchemaInterface> {}
4646

4747
/**
4848
* Final format for Schema params passed to backend requests.
49-
* @internal
49+
* @public
5050
*/
51-
// eslint-disable-next-line @typescript-eslint/naming-convention
52-
export interface _SchemaRequest extends SchemaShared<_SchemaRequest> {
51+
export interface SchemaRequest extends SchemaShared<SchemaRequest> {
5352
/**
5453
* The type of the property. {@link
5554
* SchemaType}.

0 commit comments

Comments
 (0)