diff --git a/src/fallbackServiceStub.ts b/src/fallbackServiceStub.ts index 78936d218..e085cf6c2 100644 --- a/src/fallbackServiceStub.ts +++ b/src/fallbackServiceStub.ts @@ -171,7 +171,8 @@ export function generateServiceStub( } }); } - }); + }) + .catch((err: unknown) => callback(err)); if (rpc.responseStream) { return streamArrayParser; diff --git a/test/unit/grpc-fallback.ts b/test/unit/grpc-fallback.ts index d806271e6..15aae44a7 100644 --- a/test/unit/grpc-fallback.ts +++ b/test/unit/grpc-fallback.ts @@ -284,7 +284,7 @@ describe('grpc-fallback', () => { }); }); - it('should handle an error', done => { + it('should handle an API error', done => { const requestObject = {content: 'test-content'}; // example of an actual google.rpc.Status error message returned by Language API const fixtureName = path.resolve(__dirname, '..', 'fixtures', 'error.bin'); @@ -327,6 +327,18 @@ describe('grpc-fallback', () => { }); }); + it('should handle a fetch error', done => { + const requestObject = {content: 'test-content'}; + //@ts-ignore + sinon.stub(nodeFetch, 'Promise').rejects(new Error('fetch error')); + gaxGrpc.createStub(echoService, stubOptions).then(echoStub => { + echoStub.echo(requestObject, {}, {}, (err?: Error) => { + assert.strictEqual(err?.message, 'fetch error'); + done(); + }); + }); + }); + it('should promote ErrorInfo if exist in fallback-rest error', done => { const requestObject = {content: 'test-content'}; // example of an actual google.rpc.Status error message returned by Translate API