I want to handle errors during fetching data about users. When there is no internet connection it works great but when there is a problem like for e.g. there is no searching object in my Firestore database function doesn't throw any exception. How I can detect timeout or other errors?
@ExperimentalCoroutinesApi override suspend fun getUserData(): Flow<FirebaseEventResponse> = callbackFlow { try { val userId = firebaseAuth.currentUser?.uid.toString() firebaseInstance.collection(userCollection).document(userId + "loremIpsu").get().addOnCompleteListener { if (it.isSuccessful) { if (it.result.metadata.isFromCache) { trySend(ExceptionOccurred.NetworkEvent(Exception())) } else { trySend(SuccessDocument(it.result)) } } else { trySend(ExceptionOccurred.Event(Exception())) } } } catch (e: Exception) { trySend(Event(e)) } awaitClose { this.cancel() } }