Skip to content

Commit 3264492

Browse files
Retry all non-Firestore exceptions (#2288)
1 parent 4ecd58e commit 3264492

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

packages/firestore/src/local/simple_db.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,23 +294,26 @@ export class SimpleDb {
294294
// caller.
295295
await transaction.completionPromise;
296296
return transactionFnResult;
297-
} catch (e) {
297+
} catch (error) {
298298
// TODO(schmidt-sebastian): We could probably be smarter about this and
299299
// not retry exceptions that are likely unrecoverable (such as quota
300300
// exceeded errors).
301+
302+
// Note: We cannot use an instanceof check for FirestoreException, since the
303+
// exception is wrapped in a generic error by our async/await handling.
301304
const retryable =
302305
idempotent &&
303-
isDomException(e) &&
306+
error.name !== 'FirebaseError' &&
304307
attemptNumber < TRANSACTION_RETRY_COUNT;
305308
debug(
306309
LOG_TAG,
307310
'Transaction failed with error: %s. Retrying: %s.',
308-
e.message,
311+
error.message,
309312
retryable
310313
);
311314

312315
if (!retryable) {
313-
return Promise.reject(e);
316+
return Promise.reject(error);
314317
}
315318
}
316319
}
@@ -801,13 +804,3 @@ function checkForAndReportiOSError(error: DOMException): Error {
801804
}
802805
return error;
803806
}
804-
805-
/** Checks whether an error is a DOMException (e.g. as thrown by IndexedDb). */
806-
function isDomException(error: Error): boolean {
807-
// DOMException is not a global type in Node with persistence, and hence we
808-
// check the constructor name if the type in unknown.
809-
return (
810-
(typeof DOMException !== 'undefined' && error instanceof DOMException) ||
811-
error.constructor.name === 'DOMException'
812-
);
813-
}

packages/firestore/test/unit/local/simple_db.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import { PersistencePromise } from '../../../src/local/persistence_promise';
2929

3030
import { fail } from '../../../src/util/assert';
31+
import { Code, FirestoreError } from '../../../src/util/error';
3132

3233
use(chaiAsPromised);
3334

@@ -551,8 +552,8 @@ describe('SimpleDb', () => {
551552
await expect(
552553
db.runTransaction('readwrite-idempotent', ['users'], txn => {
553554
++attemptCount;
554-
txn.abort();
555-
return PersistencePromise.reject(new Error('Aborted'));
555+
txn.abort(new FirestoreError(Code.ABORTED, 'Aborted'));
556+
return PersistencePromise.reject(new Error());
556557
})
557558
).to.eventually.be.rejected;
558559

0 commit comments

Comments
 (0)