Skip to content

Commit

Permalink
fix: handle fetch errors (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesnash committed Jul 18, 2022
1 parent a41ea4c commit 39b06dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/fallbackServiceStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ export function generateServiceStub(
}
});
}
});
})
.catch((err: unknown) => callback(err));

if (rpc.responseStream) {
return streamArrayParser;
Expand Down
14 changes: 13 additions & 1 deletion test/unit/grpc-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 39b06dd

Please sign in to comment.