Socket
Socket
Sign inDemoInstall

google-gax

Package Overview
Dependencies
Maintainers
3
Versions
362
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-gax - npm Package Compare versions

Comparing version 3.0.2 to 3.0.3

5

build/src/googleError.d.ts

@@ -20,2 +20,3 @@ /**

import { Metadata } from './grpc';
import { JSONValue } from 'proto3-json-serializer';
export declare class GoogleError extends Error {

@@ -70,3 +71,7 @@ code?: Status;

decodeGRPCStatusDetails(bufferArr: Buffer[] | ArrayBuffer[]): GRPCStatusDetailsObject;
decodeHTTPError(json: JSONValue): {
[k: string]: any;
};
decodeHttpStatusDetails(rawDetails: Array<ProtobufAny>): GRPCStatusDetailsObject;
}
export {};

77

build/src/googleError.js

@@ -21,2 +21,4 @@ "use strict";

const protobuf = require("protobufjs");
const serializer = require("proto3-json-serializer");
const fallback_1 = require("./fallback");
class GoogleError extends Error {

@@ -50,3 +52,11 @@ // Parse details field in google.rpc.status wire over gRPC medatadata.

static parseHttpError(json) {
const error = Object.assign(new GoogleError(json['error']['message']), json.error);
if (Array.isArray(json)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
json = json.find((obj) => {
return 'error' in obj;
});
}
const decoder = new GoogleErrorDecoder();
const proto3Error = decoder.decodeHTTPError(json['error']);
const error = Object.assign(new GoogleError(json['error']['message']), proto3Error);
// Map Http Status Code to gRPC Status Code

@@ -56,17 +66,29 @@ if (json['error']['code']) {

}
else {
// If error code is absent, proto3 message default value is 0. We should
// keep error code as undefined.
delete error.code;
}
// Keep consistency with gRPC statusDetails fields. gRPC details has been occupied before.
// Rename "detials" to "statusDetails".
error.statusDetails = json['error']['details'];
delete error.details;
// Promote the ErrorInfo fields as error's top-level.
const errorInfo = !json['error']['details']
? undefined
: json['error']['details'].find((item) => item['@type'] === 'type.googleapis.com/google.rpc.ErrorInfo');
if (errorInfo) {
error.reason = errorInfo.reason;
error.domain = errorInfo.domain;
// error.metadata has been occupied for gRPC metadata, so we use
// errorInfoMetadat to represent ErrorInfo' metadata field. Keep
// consistency with gRPC ErrorInfo metadata field name.
error.errorInfoMetadata = errorInfo.metadata;
if (error.details) {
try {
const statusDetailsObj = decoder.decodeHttpStatusDetails(error.details);
if (statusDetailsObj &&
statusDetailsObj.details &&
statusDetailsObj.details.length > 0) {
error.statusDetails = statusDetailsObj.details;
}
if (statusDetailsObj && statusDetailsObj.errorInfo) {
error.reason = statusDetailsObj.errorInfo.reason;
error.domain = statusDetailsObj.errorInfo.domain;
// error.metadata has been occupied for gRPC metadata, so we use
// errorInfoMetadata to represent ErrorInfo' metadata field. Keep
// consistency with gRPC ErrorInfo metadata field name.
error.errorInfoMetadata = statusDetailsObj.errorInfo.metadata;
}
}
catch (decodeErr) {
// ignoring the error
}
}

@@ -164,4 +186,31 @@ return error;

}
// Decodes http error which is an instance of google.rpc.Status.
decodeHTTPError(json) {
const errorMessage = serializer.fromProto3JSON(this.statusType, json);
if (!errorMessage) {
throw new Error(`Received error message ${json}, but failed to serialize as proto3 message`);
}
return this.statusType.toObject(errorMessage, fallback_1.defaultToObjectOptions);
}
// Decodes http error details which is an instance of Array<google.protobuf.Any>.
decodeHttpStatusDetails(rawDetails) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const details = [];
let errorInfo;
for (const detail of rawDetails) {
try {
const decodedDetail = this.decodeProtobufAny(detail);
details.push(decodedDetail);
if (detail.type_url === 'type.googleapis.com/google.rpc.ErrorInfo') {
errorInfo = decodedDetail;
}
}
catch (err) {
// cannot decode detail, likely because of the unknown type - just skip it
}
}
return { details, errorInfo };
}
}
exports.GoogleErrorDecoder = GoogleErrorDecoder;
//# sourceMappingURL=googleError.js.map

2

build/src/grpc.d.ts

@@ -123,3 +123,3 @@ /**

loadProtoJSON(json: protobuf.INamespace, ignoreCache?: boolean): grpc.GrpcObject;
metadataBuilder(headers: OutgoingHttpHeaders): (abTests?: {} | undefined, moreHeaders?: OutgoingHttpHeaders | undefined) => grpc.Metadata;
metadataBuilder(headers: OutgoingHttpHeaders): (abTests?: {}, moreHeaders?: OutgoingHttpHeaders) => grpc.Metadata;
/**

@@ -126,0 +126,0 @@ * A wrapper of {@link constructSettings} function under the gRPC context.

@@ -17,2 +17,4 @@ /**

/// <reference types="node" />
/// <reference types="node" />
import { AbortController as NodeAbortController } from 'abort-controller';
import { Transform } from 'stream';

@@ -26,3 +28,3 @@ export declare class StreamArrayParser extends Transform {

rpc: protobuf.Method;
cancelController: AbortController;
cancelController: AbortController | NodeAbortController;
cancelSignal: AbortSignal;

@@ -29,0 +31,0 @@ cancelRequested: boolean;

@@ -54,4 +54,3 @@ "use strict";

this.cancelController = (0, featureDetection_1.hasAbortController)()
? // eslint-disable-next-line no-undef
new AbortController()
? new AbortController()
: new abort_controller_1.AbortController();

@@ -58,0 +57,0 @@ this.cancelSignal = this.cancelController.signal;

@@ -19,2 +19,3 @@ "use strict";

exports.StreamProxy = exports.StreamType = void 0;
const googleError_1 = require("../googleError");
// eslint-disable-next-line @typescript-eslint/no-var-requires

@@ -104,2 +105,5 @@ const duplexify = require('duplexify');

});
stream.on('error', error => {
googleError_1.GoogleError.parseGRPCStatusDetails(error);
});
}

@@ -106,0 +110,0 @@ /**

{
"name": "google-gax",
"version": "3.0.2",
"version": "3.0.3",
"description": "Google API Extensions",

@@ -5,0 +5,0 @@ "main": "build/src/index.js",

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

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc