@@ -471,25 +471,30 @@ inline fun <R> rethrow(function: () -> R): R {
471
471
}
472
472
}
473
473
474
- fun errorToException (e : dynamic ) = when (e?.code?.toString()?.toLowerCase()) {
475
- " cancelled" -> FirebaseFirestoreException (e, FirestoreExceptionCode .CANCELLED )
476
- " invalid-argument" -> FirebaseFirestoreException (e, FirestoreExceptionCode .INVALID_ARGUMENT )
477
- " deadline-exceeded" -> FirebaseFirestoreException (e, FirestoreExceptionCode .DEADLINE_EXCEEDED )
478
- " not-found" -> FirebaseFirestoreException (e, FirestoreExceptionCode .NOT_FOUND )
479
- " already-exists" -> FirebaseFirestoreException (e, FirestoreExceptionCode .ALREADY_EXISTS )
480
- " permission-denied" -> FirebaseFirestoreException (e, FirestoreExceptionCode .PERMISSION_DENIED )
481
- " resource-exhausted" -> FirebaseFirestoreException (e, FirestoreExceptionCode .RESOURCE_EXHAUSTED )
482
- " failed-precondition" -> FirebaseFirestoreException (e, FirestoreExceptionCode .FAILED_PRECONDITION )
483
- " aborted" -> FirebaseFirestoreException (e, FirestoreExceptionCode .ABORTED )
484
- " out-of-range" -> FirebaseFirestoreException (e, FirestoreExceptionCode .OUT_OF_RANGE )
485
- " unimplemented" -> FirebaseFirestoreException (e, FirestoreExceptionCode .UNIMPLEMENTED )
486
- " internal" -> FirebaseFirestoreException (e, FirestoreExceptionCode .INTERNAL )
487
- " unavailable" -> FirebaseFirestoreException (e, FirestoreExceptionCode .UNAVAILABLE )
488
- " data-loss" -> FirebaseFirestoreException (e, FirestoreExceptionCode .DATA_LOSS )
489
- " unauthenticated" -> FirebaseFirestoreException (e, FirestoreExceptionCode .UNAUTHENTICATED )
490
- " unknown" -> FirebaseFirestoreException (e, FirestoreExceptionCode .UNKNOWN )
491
- else -> {
492
- println (" Unknown error code in ${JSON .stringify(e)} " )
493
- FirebaseFirestoreException (e, FirestoreExceptionCode .UNKNOWN )
494
- }
474
+ fun errorToException (e : dynamic ) = (e?.code ? : e?.message ? : " " )
475
+ .toString()
476
+ .toLowerCase()
477
+ .let {
478
+ when {
479
+ " cancelled" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .CANCELLED )
480
+ " invalid-argument" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .INVALID_ARGUMENT )
481
+ " deadline-exceeded" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .DEADLINE_EXCEEDED )
482
+ " not-found" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .NOT_FOUND )
483
+ " already-exists" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .ALREADY_EXISTS )
484
+ " permission-denied" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .PERMISSION_DENIED )
485
+ " resource-exhausted" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .RESOURCE_EXHAUSTED )
486
+ " failed-precondition" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .FAILED_PRECONDITION )
487
+ " aborted" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .ABORTED )
488
+ " out-of-range" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .OUT_OF_RANGE )
489
+ " unimplemented" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .UNIMPLEMENTED )
490
+ " internal" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .INTERNAL )
491
+ " unavailable" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .UNAVAILABLE )
492
+ " data-loss" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .DATA_LOSS )
493
+ " unauthenticated" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .UNAUTHENTICATED )
494
+ " unknown" in it -> FirebaseFirestoreException (e, FirestoreExceptionCode .UNKNOWN )
495
+ else -> {
496
+ println (" Unknown error code in ${JSON .stringify(e)} " )
497
+ FirebaseFirestoreException (e, FirestoreExceptionCode .UNKNOWN )
498
+ }
499
+ }
495
500
}
0 commit comments