@@ -378,8 +378,9 @@ export class SimpleDbTransaction {
378
378
}
379
379
} ;
380
380
this . transaction . onerror = ( event : Event ) => {
381
- const error = ( event . target as IDBRequest ) . error ! ;
382
- checkForAndReportiOSError ( error ) ;
381
+ const error = checkForAndReportiOSError (
382
+ ( event . target as IDBRequest ) . error !
383
+ ) ;
383
384
this . completionDeferred . reject ( error ) ;
384
385
} ;
385
386
}
@@ -599,8 +600,9 @@ export class SimpleDbStore<
599
600
const cursorRequest = this . cursor ( { } ) ;
600
601
return new PersistencePromise ( ( resolve , reject ) => {
601
602
cursorRequest . onerror = ( event : Event ) => {
602
- const error = ( event . target as IDBRequest ) . error ! ;
603
- checkForAndReportiOSError ( error ) ;
603
+ const error = checkForAndReportiOSError (
604
+ ( event . target as IDBRequest ) . error !
605
+ ) ;
604
606
reject ( error ) ;
605
607
} ;
606
608
cursorRequest . onsuccess = ( event : Event ) => {
@@ -715,35 +717,39 @@ function wrapRequest<R>(request: IDBRequest): PersistencePromise<R> {
715
717
} ;
716
718
717
719
request . onerror = ( event : Event ) => {
718
- const error = ( event . target as IDBRequest ) . error ! ;
719
- checkForAndReportiOSError ( error ) ;
720
+ const error = checkForAndReportiOSError (
721
+ ( event . target as IDBRequest ) . error !
722
+ ) ;
720
723
reject ( error ) ;
721
724
} ;
722
725
} ) ;
723
726
}
724
727
725
728
// Guard so we only report the error once.
726
729
let reportedIOSError = false ;
727
- function checkForAndReportiOSError ( error : DOMException ) : void {
728
- if ( reportedIOSError ) {
729
- return ;
730
- }
730
+ function checkForAndReportiOSError ( error : DOMException ) : Error {
731
731
const iOSVersion = SimpleDb . getIOSVersion ( getUA ( ) ) ;
732
732
if ( iOSVersion >= 12.2 && iOSVersion < 13 ) {
733
733
const IOS_ERROR =
734
734
'An internal error was encountered in the Indexed Database server' ;
735
735
if ( error . message . indexOf ( IOS_ERROR ) >= 0 ) {
736
- reportedIOSError = true ;
737
- // Throw a global exception outside of this promise chain, for the user to
738
- // potentially catch.
739
- setTimeout ( ( ) => {
740
- throw new FirestoreError (
741
- 'internal' ,
742
- `IOS_INDEXEDDB_BUG1: IndexedDb has thrown '${ IOS_ERROR } '. This is likely ` +
743
- `due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 ` +
744
- `for details and a potential workaround.`
745
- ) ;
746
- } , 0 ) ;
736
+ // Wrap error in a more descriptive one.
737
+ const newError = new FirestoreError (
738
+ 'internal' ,
739
+ `IOS_INDEXEDDB_BUG1: IndexedDb has thrown '${ IOS_ERROR } '. This is likely ` +
740
+ `due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 ` +
741
+ `for details and a potential workaround.`
742
+ ) ;
743
+ if ( ! reportedIOSError ) {
744
+ reportedIOSError = true ;
745
+ // Throw a global exception outside of this promise chain, for the user to
746
+ // potentially catch.
747
+ setTimeout ( ( ) => {
748
+ throw newError ;
749
+ } , 0 ) ;
750
+ }
751
+ return newError ;
747
752
}
748
753
}
754
+ return error ;
749
755
}
0 commit comments