Skip to content

Commit c3a3037

Browse files
committed
Rename httpErrorData to customErrorData to make more future-proof
1 parent c01003c commit c3a3037

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

packages/vertexai/src/errors.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import { FirebaseError } from '@firebase/util';
1919
import {
2020
VertexAIErrorCode,
21-
GenerateContentResponse,
22-
HTTPErrorDetails
21+
CustomErrorData
2322
} from './types';
2423
import { VERTEX_TYPE } from './constants';
2524

@@ -34,14 +33,12 @@ export class VertexAIError extends FirebaseError {
3433
*
3534
* @param code - The error code from {@link VertexAIErrorCode}.
3635
* @param message - A human-readable message describing the error.
37-
* @param HTTPErrorDetails - Optional HTTP details from a bad response.
38-
* @param generateContentResponse - Optional response from a {@link GenerateContentRequest}.
36+
* @param customErrorData - Optional error data.
3937
*/
4038
constructor(
4139
readonly code: VertexAIErrorCode,
4240
readonly message: string,
43-
readonly httpErrorDetails?: HTTPErrorDetails,
44-
readonly generateContentResponse?: GenerateContentResponse
41+
readonly customErrorData?: CustomErrorData,
4542
) {
4643
// Match error format used by FirebaseError from ErrorFactory
4744
const service = VERTEX_TYPE;

packages/vertexai/src/requests/request.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ describe('request methods', () => {
249249
expect((e as VertexAIError).code).to.equal(
250250
VertexAIErrorCode.FETCH_ERROR
251251
);
252-
expect((e as VertexAIError).httpErrorDetails?.status).to.equal(500);
253-
expect((e as VertexAIError).httpErrorDetails?.statusText).to.equal(
252+
expect((e as VertexAIError).customErrorData?.status).to.equal(500);
253+
expect((e as VertexAIError).customErrorData?.statusText).to.equal(
254254
'AbortError'
255255
);
256256
expect((e as VertexAIError).message).to.include('500 AbortError');
@@ -276,8 +276,8 @@ describe('request methods', () => {
276276
expect((e as VertexAIError).code).to.equal(
277277
VertexAIErrorCode.FETCH_ERROR
278278
);
279-
expect((e as VertexAIError).httpErrorDetails?.status).to.equal(500);
280-
expect((e as VertexAIError).httpErrorDetails?.statusText).to.equal(
279+
expect((e as VertexAIError).customErrorData?.status).to.equal(500);
280+
expect((e as VertexAIError).customErrorData?.statusText).to.equal(
281281
'Server Error'
282282
);
283283
expect((e as VertexAIError).message).to.include('500 Server Error');
@@ -303,8 +303,8 @@ describe('request methods', () => {
303303
expect((e as VertexAIError).code).to.equal(
304304
VertexAIErrorCode.FETCH_ERROR
305305
);
306-
expect((e as VertexAIError).httpErrorDetails?.status).to.equal(500);
307-
expect((e as VertexAIError).httpErrorDetails?.statusText).to.equal(
306+
expect((e as VertexAIError).customErrorData?.status).to.equal(500);
307+
expect((e as VertexAIError).customErrorData?.statusText).to.equal(
308308
'Server Error'
309309
);
310310
expect((e as VertexAIError).message).to.include('500 Server Error');
@@ -343,8 +343,8 @@ describe('request methods', () => {
343343
expect((e as VertexAIError).code).to.equal(
344344
VertexAIErrorCode.FETCH_ERROR
345345
);
346-
expect((e as VertexAIError).httpErrorDetails?.status).to.equal(500);
347-
expect((e as VertexAIError).httpErrorDetails?.statusText).to.equal(
346+
expect((e as VertexAIError).customErrorData?.status).to.equal(500);
347+
expect((e as VertexAIError).customErrorData?.statusText).to.equal(
348348
'Server Error'
349349
);
350350
expect((e as VertexAIError).message).to.include('500 Server Error');

packages/vertexai/src/requests/response-helpers.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,19 @@ export function addHelpers(
4747
`Response error: ${formatBlockErrorMessage(
4848
response
4949
)}. Response body stored in error.generateContentResponse`,
50-
undefined,
51-
response
50+
{
51+
generateContentResponse: response
52+
}
5253
);
5354
}
5455
return getText(response);
5556
} else if (response.promptFeedback) {
5657
throw new VertexAIError(
5758
VertexAIErrorCode.RESPONSE_ERROR,
5859
`Text not available. ${formatBlockErrorMessage(response)}`,
59-
undefined,
60-
response
60+
{
61+
generateContentResponse: response
62+
}
6163
);
6264
}
6365
return '';
@@ -77,17 +79,19 @@ export function addHelpers(
7779
`Response error: ${formatBlockErrorMessage(
7880
response
7981
)}. Response body stored in error.generateContentResponse`,
80-
undefined,
81-
response
82+
{
83+
generateContentResponse: response
84+
}
8285
);
8386
}
8487
return getFunctionCalls(response);
8588
} else if (response.promptFeedback) {
8689
throw new VertexAIError(
8790
VertexAIErrorCode.RESPONSE_ERROR,
8891
`Function call not available. ${formatBlockErrorMessage(response)}`,
89-
undefined,
90-
response
92+
{
93+
generateContentResponse: response
94+
}
9195
);
9296
}
9397
return undefined;

packages/vertexai/src/types/error.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { GenerateContentResponse } from './responses';
19+
1820
/**
1921
* Details object that may be included in an error response.
2022
*
@@ -41,12 +43,15 @@ export interface ErrorDetails {
4143
*
4244
* @public
4345
*/
44-
export interface HTTPErrorDetails {
46+
export interface CustomErrorData {
4547
/** HTTP status code of the error response. */
46-
status: number;
48+
status?: number;
4749

4850
/** HTTP status text of the error response. */
49-
statusText: string;
51+
statusText?: string;
52+
53+
/** Response from a {@link GenerateContentRequest} */
54+
generateContentResponse?: GenerateContentResponse;
5055

5156
/** Optional additional details about the error. */
5257
errorDetails?: ErrorDetails[];

0 commit comments

Comments
 (0)