File tree Expand file tree Collapse file tree 2 files changed +10
-16
lines changed Expand file tree Collapse file tree 2 files changed +10
-16
lines changed Original file line number Diff line number Diff line change @@ -294,23 +294,26 @@ export class SimpleDb {
294
294
// caller.
295
295
await transaction . completionPromise ;
296
296
return transactionFnResult ;
297
- } catch ( e ) {
297
+ } catch ( error ) {
298
298
// TODO(schmidt-sebastian): We could probably be smarter about this and
299
299
// not retry exceptions that are likely unrecoverable (such as quota
300
300
// 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.
301
304
const retryable =
302
305
idempotent &&
303
- isDomException ( e ) &&
306
+ error . name !== 'FirebaseError' &&
304
307
attemptNumber < TRANSACTION_RETRY_COUNT ;
305
308
debug (
306
309
LOG_TAG ,
307
310
'Transaction failed with error: %s. Retrying: %s.' ,
308
- e . message ,
311
+ error . message ,
309
312
retryable
310
313
) ;
311
314
312
315
if ( ! retryable ) {
313
- return Promise . reject ( e ) ;
316
+ return Promise . reject ( error ) ;
314
317
}
315
318
}
316
319
}
@@ -801,13 +804,3 @@ function checkForAndReportiOSError(error: DOMException): Error {
801
804
}
802
805
return error ;
803
806
}
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
- }
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import {
28
28
import { PersistencePromise } from '../../../src/local/persistence_promise' ;
29
29
30
30
import { fail } from '../../../src/util/assert' ;
31
+ import { Code , FirestoreError } from '../../../src/util/error' ;
31
32
32
33
use ( chaiAsPromised ) ;
33
34
@@ -551,8 +552,8 @@ describe('SimpleDb', () => {
551
552
await expect (
552
553
db . runTransaction ( 'readwrite-idempotent' , [ 'users' ] , txn => {
553
554
++ 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 ( ) ) ;
556
557
} )
557
558
) . to . eventually . be . rejected ;
558
559
You can’t perform that action at this time.
0 commit comments