Skip to content

Commit

Permalink
Retrying without an error code (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Nov 30, 2017
1 parent 1e7c5d6 commit ed83393
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/watch.js
Expand Up @@ -205,14 +205,24 @@ const DOCUMENT_WATCH_COMPARATOR = (doc1, doc2) => {
};

/**
* Determines whether a GRPC Error is considered permanent and should not be
* retried.
* Determines whether an error is considered permanent and should not be
* retried. Errors that don't provide a GRPC error code are always considered
* transient in this context.
*
* @private
* @param {Error} error A GRPC Error object that exposes an error code.
* @param {Error} error An error object.
* @return {boolean} Whether the error is permanent.
*/
function isPermanentError(error) {
if (error.code === undefined) {
Firestore.log(
'Watch.onSnapshot',
'Unable to determine error code: ',
error
);
return false;
}

switch (error.code) {
case GRPC_STATUS_CODE.CANCELLED:
case GRPC_STATUS_CODE.UNKNOWN:
Expand Down
12 changes: 12 additions & 0 deletions test/watch.js
Expand Up @@ -819,6 +819,18 @@ describe('Query watch', function() {
return result;
});

it('retries with unknown code', function() {
return watchHelper.runTest(collQueryJSON(), () => {
watchHelper.sendAddTarget();
watchHelper.sendCurrent();
watchHelper.sendSnapshot(1, [0xabcd]);
return watchHelper.await('snapshot').then(() => {
streamHelper.destroyStream(new Error('Unknown'));
return streamHelper.awaitReopen();
});
});
});

it('handles changing a doc', function() {
return watchHelper.runTest(collQueryJSON(), () => {
// Mock the server responding to the query.
Expand Down

0 comments on commit ed83393

Please sign in to comment.