Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle fetch errors #1294

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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