Skip to content

Commit

Permalink
feat: add dynamic upStreamCodes option (#618)
Browse files Browse the repository at this point in the history
* feat: add dynamic upStreamCodes option

* fix default value upStreamCodes

* update examples

Co-authored-by: Francois HERSENT <francois.hersent@hiventive.com>
  • Loading branch information
hersentino and hersentino committed Jul 19, 2022
1 parent 080ce5f commit 3091023
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions integration/grpc-web-no-streaming-observable/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export class GrpcWebImpl {

debug?: boolean;
metadata?: grpc.Metadata;
upStreamRetryCodes?: number[];
};

constructor(
Expand All @@ -378,6 +379,7 @@ export class GrpcWebImpl {

debug?: boolean;
metadata?: grpc.Metadata;
upStreamRetryCodes?: number[];
}
) {
this.host = host;
Expand Down
2 changes: 2 additions & 0 deletions integration/grpc-web-no-streaming/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ export class GrpcWebImpl {

debug?: boolean;
metadata?: grpc.Metadata;
upStreamRetryCodes?: number[];
};

constructor(
Expand All @@ -376,6 +377,7 @@ export class GrpcWebImpl {

debug?: boolean;
metadata?: grpc.Metadata;
upStreamRetryCodes?: number[];
}
) {
this.host = host;
Expand Down
5 changes: 3 additions & 2 deletions integration/grpc-web/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ export class GrpcWebImpl {
streamingTransport?: grpc.TransportFactory;
debug?: boolean;
metadata?: grpc.Metadata;
upStreamRetryCodes?: number[];
};

constructor(
Expand All @@ -816,6 +817,7 @@ export class GrpcWebImpl {
streamingTransport?: grpc.TransportFactory;
debug?: boolean;
metadata?: grpc.Metadata;
upStreamRetryCodes?: number[];
}
) {
this.host = host;
Expand Down Expand Up @@ -858,8 +860,7 @@ export class GrpcWebImpl {
_request: any,
metadata: grpc.Metadata | undefined
): Observable<any> {
// 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 =
Expand Down
4 changes: 2 additions & 2 deletions src/generate-grpc-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ function generateGrpcWebImpl(ctx: Context, returnObservable: boolean, hasStreami
${hasStreamingMethods ? 'streamingTransport?: grpc.TransportFactory,' : ``}
debug?: boolean,
metadata?: grpc.Metadata,
upStreamRetryCodes?: number[],
}
`;

Expand Down Expand Up @@ -299,8 +300,7 @@ function createInvokeMethod(ctx: Context) {
_request: any,
metadata: grpc.Metadata | undefined
): ${observableType(ctx)}<any> {
// 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 =
Expand Down

0 comments on commit 3091023

Please sign in to comment.