@google-cloud/vertexai
Advanced tools
Comparing version 1.6.0 to 1.7.0
{ | ||
".": "1.6.0" | ||
".": "1.7.0" | ||
} |
@@ -32,3 +32,4 @@ "use strict"; | ||
if (status >= 400 && status < 500) { | ||
throw new errors_1.ClientError(errorMessage); | ||
const error = new errors_1.ClientError(errorMessage, new errors_1.GoogleApiError(errorBody.error.message, errorBody.error.code, errorBody.error.status, errorBody.error.details)); | ||
throw error; | ||
} | ||
@@ -35,0 +36,0 @@ throw new errors_1.GoogleGenerativeAIError(errorMessage); |
@@ -260,9 +260,21 @@ "use strict"; | ||
const body = { | ||
code: 400, | ||
message: 'request is invalid', | ||
status: 'INVALID_ARGUMENT', | ||
error: { | ||
code: 400, | ||
message: 'request is invalid', | ||
status: 'INVALID_ARGUMENT', | ||
}, | ||
}; | ||
const response = new Response(JSON.stringify(body), fetch400Obj); | ||
spyOn(global, 'fetch').and.resolveTo(response); | ||
await expectAsync((0, count_tokens_1.countTokens)(TEST_LOCATION, TEST_RESOURCE_PATH, TEST_TOKEN_PROMISE, req, TEST_API_ENDPOINT)).toBeRejected(); | ||
let error; | ||
try { | ||
await (0, count_tokens_1.countTokens)(TEST_LOCATION, TEST_RESOURCE_PATH, TEST_TOKEN_PROMISE, req, TEST_API_ENDPOINT); | ||
} | ||
catch (e) { | ||
error = e; | ||
} | ||
expect(error).toBeInstanceOf(types_1.ClientError); | ||
expect(error.cause).toBeInstanceOf(types_1.GoogleApiError); | ||
expect(error.cause.code).toBe(400); | ||
expect(error.cause.status).toEqual('INVALID_ARGUMENT'); | ||
}); | ||
@@ -269,0 +281,0 @@ }); |
@@ -33,2 +33,24 @@ /** | ||
/** | ||
* Google API Error Details object that may be included in an error response. | ||
* See https://cloud.google.com/apis/design/errors | ||
* @public | ||
*/ | ||
export declare interface ErrorDetails { | ||
'@type'?: string; | ||
reason?: string; | ||
domain?: string; | ||
metadata?: Record<string, unknown>; | ||
[key: string]: unknown; | ||
} | ||
/** | ||
* GoogleApiError is thrown when http 4XX status is received. | ||
* See https://cloud.google.com/apis/design/errors | ||
*/ | ||
declare class GoogleApiError extends Error { | ||
code?: number | undefined; | ||
status?: string | undefined; | ||
errorDetails?: ErrorDetails[] | undefined; | ||
constructor(message: string, code?: number | undefined, status?: string | undefined, errorDetails?: ErrorDetails[] | undefined); | ||
} | ||
/** | ||
* GoogleGenerativeAIError is thrown when http response is not ok and status code is not 4XX | ||
@@ -48,2 +70,2 @@ * For details please refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Status | ||
} | ||
export { ClientError, GoogleAuthError, GoogleGenerativeAIError, IllegalArgumentError, }; | ||
export { ClientError, GoogleApiError, GoogleAuthError, GoogleGenerativeAIError, IllegalArgumentError, }; |
@@ -19,3 +19,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.IllegalArgumentError = exports.GoogleGenerativeAIError = exports.GoogleAuthError = exports.ClientError = void 0; | ||
exports.IllegalArgumentError = exports.GoogleGenerativeAIError = exports.GoogleAuthError = exports.GoogleApiError = exports.ClientError = void 0; | ||
/** | ||
@@ -47,2 +47,15 @@ * GoogleAuthError is thrown when there is authentication issue with the request | ||
/** | ||
* GoogleApiError is thrown when http 4XX status is received. | ||
* See https://cloud.google.com/apis/design/errors | ||
*/ | ||
class GoogleApiError extends Error { | ||
constructor(message, code, status, errorDetails) { | ||
super(message); | ||
this.code = code; | ||
this.status = status; | ||
this.errorDetails = errorDetails; | ||
} | ||
} | ||
exports.GoogleApiError = GoogleApiError; | ||
/** | ||
* GoogleGenerativeAIError is thrown when http response is not ok and status code is not 4XX | ||
@@ -49,0 +62,0 @@ * For details please refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Status |
@@ -23,3 +23,3 @@ /** | ||
export declare const SYSTEM_ROLE = "system"; | ||
export declare const USER_AGENT = "model-builder/1.6.0 grpc-node/1.6.0"; | ||
export declare const USER_AGENT = "model-builder/1.7.0 grpc-node/1.7.0"; | ||
export declare const CREDENTIAL_ERROR_MESSAGE = "\nUnable to authenticate your request \nDepending on your run time environment, you can get authentication by \n- if in local instance or cloud shell: `!gcloud auth login` \n- if in Colab: \n -`from google.colab import auth` \n -`auth.authenticate_user()` \n- if in service account or other: please follow guidance in https://cloud.google.com/docs/authentication"; |
@@ -27,3 +27,3 @@ "use strict"; | ||
const USER_AGENT_PRODUCT = 'model-builder'; | ||
const CLIENT_LIBRARY_VERSION = '1.6.0'; // x-release-please-version | ||
const CLIENT_LIBRARY_VERSION = '1.7.0'; // x-release-please-version | ||
const CLIENT_LIBRARY_LANGUAGE = `grpc-node/${CLIENT_LIBRARY_VERSION}`; | ||
@@ -30,0 +30,0 @@ exports.USER_AGENT = `${USER_AGENT_PRODUCT}/${CLIENT_LIBRARY_VERSION} ${CLIENT_LIBRARY_LANGUAGE}`; |
@@ -232,2 +232,6 @@ "use strict"; | ||
got wrong error message: ${e.message}`); | ||
expect(e.cause).toBeInstanceOf(src_1.GoogleApiError); | ||
expect(e.cause.code).toBe(400); | ||
expect(e.cause.status).toBe('INVALID_ARGUMENT'); | ||
expect(e.cause.message).toBeInstanceOf(String); | ||
}); | ||
@@ -253,2 +257,6 @@ }); | ||
got wrong error message: ${e.message}`); | ||
expect(e.cause).toBeInstanceOf(src_1.GoogleApiError); | ||
expect(e.cause.code).toBe(400); | ||
expect(e.cause.status).toBe('INVALID_ARGUMENT'); | ||
expect(e.cause.message).toBeInstanceOf(String); | ||
}); | ||
@@ -255,0 +263,0 @@ }); |
# Changelog | ||
## [1.7.0](https://github.com/googleapis/nodejs-vertexai/compare/v1.6.0...v1.7.0) (2024-08-30) | ||
### Features | ||
* Add GoogleApi error in ClientError.cause ([d5c67bd](https://github.com/googleapis/nodejs-vertexai/commit/d5c67bdbb7d40f0c8eecca505c90bac21e4fe36d)) | ||
## [1.6.0](https://github.com/googleapis/nodejs-vertexai/compare/v1.5.0...v1.6.0) (2024-08-26) | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "@google-cloud/vertexai", | ||
"description": "Vertex Generative AI client for Node.js", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "author": "Google LLC", |
@@ -29,3 +29,7 @@ /** | ||
import {constants} from '../util'; | ||
import {ClientError, GoogleGenerativeAIError} from '../types/errors'; | ||
import { | ||
ClientError, | ||
GoogleApiError, | ||
GoogleGenerativeAIError, | ||
} from '../types/errors'; | ||
@@ -44,3 +48,12 @@ export async function throwErrorIfNotOK(response: Response | undefined) { | ||
if (status >= 400 && status < 500) { | ||
throw new ClientError(errorMessage); | ||
const error = new ClientError( | ||
errorMessage, | ||
new GoogleApiError( | ||
errorBody.error.message, | ||
errorBody.error.code, | ||
errorBody.error.status, | ||
errorBody.error.details | ||
) | ||
); | ||
throw error; | ||
} | ||
@@ -47,0 +60,0 @@ throw new GoogleGenerativeAIError(errorMessage); |
@@ -19,2 +19,3 @@ /** | ||
import { | ||
ClientError, | ||
CountTokensRequest, | ||
@@ -27,2 +28,3 @@ FinishReason, | ||
GenerateContentResult, | ||
GoogleApiError, | ||
HarmBlockThreshold, | ||
@@ -329,5 +331,7 @@ HarmCategory, | ||
const body = { | ||
code: 400, | ||
message: 'request is invalid', | ||
status: 'INVALID_ARGUMENT', | ||
error: { | ||
code: 400, | ||
message: 'request is invalid', | ||
status: 'INVALID_ARGUMENT', | ||
}, | ||
}; | ||
@@ -337,4 +341,5 @@ const response = new Response(JSON.stringify(body), fetch400Obj); | ||
await expectAsync( | ||
countTokens( | ||
let error: any; | ||
try { | ||
await countTokens( | ||
TEST_LOCATION, | ||
@@ -345,4 +350,11 @@ TEST_RESOURCE_PATH, | ||
TEST_API_ENDPOINT | ||
) | ||
).toBeRejected(); | ||
); | ||
} catch (e) { | ||
error = e; | ||
} | ||
expect(error).toBeInstanceOf(ClientError); | ||
expect(error.cause).toBeInstanceOf(GoogleApiError); | ||
expect(error.cause.code).toBe(400); | ||
expect(error.cause.status).toEqual('INVALID_ARGUMENT'); | ||
}); | ||
@@ -349,0 +361,0 @@ }); |
@@ -46,2 +46,30 @@ /** | ||
/** | ||
* Google API Error Details object that may be included in an error response. | ||
* See https://cloud.google.com/apis/design/errors | ||
* @public | ||
*/ | ||
export declare interface ErrorDetails { | ||
'@type'?: string; | ||
reason?: string; | ||
domain?: string; | ||
metadata?: Record<string, unknown>; | ||
[key: string]: unknown; | ||
} | ||
/** | ||
* GoogleApiError is thrown when http 4XX status is received. | ||
* See https://cloud.google.com/apis/design/errors | ||
*/ | ||
class GoogleApiError extends Error { | ||
constructor( | ||
message: string, | ||
public code?: number, | ||
public status?: string, | ||
public errorDetails?: ErrorDetails[] | ||
) { | ||
super(message); | ||
} | ||
} | ||
/** | ||
* GoogleGenerativeAIError is thrown when http response is not ok and status code is not 4XX | ||
@@ -82,2 +110,3 @@ * For details please refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Status | ||
ClientError, | ||
GoogleApiError, | ||
GoogleAuthError, | ||
@@ -84,0 +113,0 @@ GoogleGenerativeAIError, |
@@ -24,3 +24,3 @@ /** | ||
const USER_AGENT_PRODUCT = 'model-builder'; | ||
const CLIENT_LIBRARY_VERSION = '1.6.0'; // x-release-please-version | ||
const CLIENT_LIBRARY_VERSION = '1.7.0'; // x-release-please-version | ||
const CLIENT_LIBRARY_LANGUAGE = `grpc-node/${CLIENT_LIBRARY_VERSION}`; | ||
@@ -27,0 +27,0 @@ export const USER_AGENT = `${USER_AGENT_PRODUCT}/${CLIENT_LIBRARY_VERSION} ${CLIENT_LIBRARY_LANGUAGE}`; |
@@ -27,2 +27,3 @@ /** | ||
GenerateContentResponseHandler, | ||
GoogleApiError, | ||
} from '../src'; | ||
@@ -349,2 +350,6 @@ import {FunctionDeclarationSchemaType} from '../src/types'; | ||
); | ||
expect(e.cause).toBeInstanceOf(GoogleApiError); | ||
expect(e.cause.code).toBe(400); | ||
expect(e.cause.status).toBe('INVALID_ARGUMENT'); | ||
expect(e.cause.message).toBeInstanceOf(String); | ||
}); | ||
@@ -373,2 +378,6 @@ }); | ||
); | ||
expect(e.cause).toBeInstanceOf(GoogleApiError); | ||
expect(e.cause.code).toBe(400); | ||
expect(e.cause.status).toBe('INVALID_ARGUMENT'); | ||
expect(e.cause.message).toBeInstanceOf(String); | ||
}); | ||
@@ -375,0 +384,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1196329
22284