diff --git a/dev/src/watch.ts b/dev/src/watch.ts index 8962770d5..739db9753 100644 --- a/dev/src/watch.ts +++ b/dev/src/watch.ts @@ -523,14 +523,15 @@ abstract class Watch { this.currentStream = backendStream; this.currentStream!.on('data', (proto: api.IListenResponse) => { this.onData(proto); - }).on('error', err => { - this.maybeReopenStream(err); - }); - this.currentStream!.on('end', () => { - const err = new GrpcError('Stream ended unexpectedly'); - err.code = GRPC_STATUS_CODE.UNKNOWN; - this.maybeReopenStream(err); - }); + }) + .on('error', err => { + this.maybeReopenStream(err); + }) + .on('end', () => { + const err = new GrpcError('Stream ended unexpectedly'); + err.code = GRPC_STATUS_CODE.UNKNOWN; + this.maybeReopenStream(err); + }); this.currentStream!.resume(); }); }) @@ -538,7 +539,11 @@ abstract class Watch { this.closeStream(err); }); } - + /** + * Handles 'data' events and closes the stream if the response type is + * invalid. + * @private + */ private onData(proto: api.IListenResponse): void { if (proto.targetChange) { logger('Watch.onSnapshot', this.requestTag, 'Processing target change');