From 309102313273e09aef3a8480f4b46360ad82adaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Tue, 19 Jul 2022 15:10:04 +0200 Subject: [PATCH] feat: add dynamic upStreamCodes option (#618) * feat: add dynamic upStreamCodes option * fix default value upStreamCodes * update examples Co-authored-by: Francois HERSENT --- integration/grpc-web-no-streaming-observable/example.ts | 2 ++ integration/grpc-web-no-streaming/example.ts | 2 ++ integration/grpc-web/example.ts | 5 +++-- src/generate-grpc-web.ts | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/integration/grpc-web-no-streaming-observable/example.ts b/integration/grpc-web-no-streaming-observable/example.ts index 384b0a7b1..cbe5fdb30 100644 --- a/integration/grpc-web-no-streaming-observable/example.ts +++ b/integration/grpc-web-no-streaming-observable/example.ts @@ -369,6 +369,7 @@ export class GrpcWebImpl { debug?: boolean; metadata?: grpc.Metadata; + upStreamRetryCodes?: number[]; }; constructor( @@ -378,6 +379,7 @@ export class GrpcWebImpl { debug?: boolean; metadata?: grpc.Metadata; + upStreamRetryCodes?: number[]; } ) { this.host = host; diff --git a/integration/grpc-web-no-streaming/example.ts b/integration/grpc-web-no-streaming/example.ts index ce091737e..fc55f0152 100644 --- a/integration/grpc-web-no-streaming/example.ts +++ b/integration/grpc-web-no-streaming/example.ts @@ -367,6 +367,7 @@ export class GrpcWebImpl { debug?: boolean; metadata?: grpc.Metadata; + upStreamRetryCodes?: number[]; }; constructor( @@ -376,6 +377,7 @@ export class GrpcWebImpl { debug?: boolean; metadata?: grpc.Metadata; + upStreamRetryCodes?: number[]; } ) { this.host = host; diff --git a/integration/grpc-web/example.ts b/integration/grpc-web/example.ts index 54bf53348..4a4ad64b4 100644 --- a/integration/grpc-web/example.ts +++ b/integration/grpc-web/example.ts @@ -807,6 +807,7 @@ export class GrpcWebImpl { streamingTransport?: grpc.TransportFactory; debug?: boolean; metadata?: grpc.Metadata; + upStreamRetryCodes?: number[]; }; constructor( @@ -816,6 +817,7 @@ export class GrpcWebImpl { streamingTransport?: grpc.TransportFactory; debug?: boolean; metadata?: grpc.Metadata; + upStreamRetryCodes?: number[]; } ) { this.host = host; @@ -858,8 +860,7 @@ export class GrpcWebImpl { _request: any, metadata: grpc.Metadata | undefined ): Observable { - // Status Response Codes (https://developers.google.com/maps-booking/reference/grpc-api/status_codes) - const upStreamCodes = [2, 4, 8, 9, 10, 13, 14, 15]; + const upStreamCodes = this.options.upStreamRetryCodes || []; const DEFAULT_TIMEOUT_TIME: number = 3_000; const request = { ..._request, ...methodDesc.requestType }; const maybeCombinedMetadata = diff --git a/src/generate-grpc-web.ts b/src/generate-grpc-web.ts index a4c2639de..435759298 100644 --- a/src/generate-grpc-web.ts +++ b/src/generate-grpc-web.ts @@ -195,6 +195,7 @@ function generateGrpcWebImpl(ctx: Context, returnObservable: boolean, hasStreami ${hasStreamingMethods ? 'streamingTransport?: grpc.TransportFactory,' : ``} debug?: boolean, metadata?: grpc.Metadata, + upStreamRetryCodes?: number[], } `; @@ -299,8 +300,7 @@ function createInvokeMethod(ctx: Context) { _request: any, metadata: grpc.Metadata | undefined ): ${observableType(ctx)} { - // Status Response Codes (https://developers.google.com/maps-booking/reference/grpc-api/status_codes) - const upStreamCodes = [2, 4, 8, 9, 10, 13, 14, 15]; + const upStreamCodes = this.options.upStreamRetryCodes || []; const DEFAULT_TIMEOUT_TIME: number = 3_000; const request = { ..._request, ...methodDesc.requestType }; const maybeCombinedMetadata =