Skip to content

Commit

Permalink
chore: 🍒 from develop - more logs sending message #WPB-11601
Browse files Browse the repository at this point in the history
  • Loading branch information
damian-kaczmarek committed Nov 26, 2024
1 parent 7440f44 commit 8d18a4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 13 additions & 9 deletions logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.wire.kalium.logic
import com.wire.kalium.cryptography.exceptions.ProteusException
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.functional.onFailure
import com.wire.kalium.network.exceptions.APINotSupported
import com.wire.kalium.network.exceptions.KaliumException
import com.wire.kalium.network.exceptions.isFederationDenied
Expand All @@ -32,6 +33,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach

sealed interface CoreFailure {

Expand Down Expand Up @@ -368,12 +370,13 @@ internal inline fun <T> wrapE2EIRequest(e2eiRequest: () -> T): Either<E2EIFailur
}

internal inline fun <T : Any> wrapStorageRequest(storageRequest: () -> T?): Either<StorageFailure, T> {
return try {
val result = try {
storageRequest()?.let { data -> Either.Right(data) } ?: Either.Left(StorageFailure.DataNotFound)
} catch (e: Exception) {
kaliumLogger.e(e.stackTraceToString())
Either.Left(StorageFailure.Generic(e))
}
result.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) }
return result
}

/**
Expand Down Expand Up @@ -404,21 +407,22 @@ internal fun <T : Any> Flow<T?>.wrapStorageRequest(): Flow<Either<StorageFailure
this.map {
it?.let { data -> Either.Right(data) } ?: Either.Left<StorageFailure>(StorageFailure.DataNotFound)
}.catch { e ->
kaliumLogger.e(e.stackTraceToString())
emit(Either.Left(StorageFailure.Generic(e)))
}.onEach {
it.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) }
}

internal inline fun <T : Any> wrapFlowStorageRequest(storageRequest: () -> Flow<T?>): Flow<Either<StorageFailure, T>> {
return try {
storageRequest().map {
it?.let { data -> Either.Right(data) } ?: Either.Left<StorageFailure>(StorageFailure.DataNotFound)
}.catch { e ->
kaliumLogger.e(e.stackTraceToString())
emit(Either.Left(StorageFailure.Generic(e)))
}
} catch (e: Exception) {
kaliumLogger.e(e.stackTraceToString())
flowOf(Either.Left(StorageFailure.Generic(e)))
}.onEach {
it.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) }
}
}

Expand All @@ -427,12 +431,12 @@ internal inline fun <T : Any> wrapNullableFlowStorageRequest(storageRequest: ()
storageRequest().map {
Either.Right(it) as Either<StorageFailure, T?>
}.catch { e ->
kaliumLogger.e(e.stackTraceToString())
emit(Either.Left(StorageFailure.Generic(e)))
emit(Either.Left<StorageFailure>(StorageFailure.Generic(e)))
}
} catch (e: Exception) {
kaliumLogger.e(e.stackTraceToString())
flowOf(Either.Left(StorageFailure.Generic(e)))
flowOf(Either.Left<StorageFailure>(StorageFailure.Generic(e)))
}.onEach {
it.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ internal class MessageSenderImpl internal constructor(
}.onSuccess {
startSelfDeletionIfNeeded(message)
}
}.onFailure {
logger.e("Failed to send message ${message::class.qualifiedName}. Failure = $it")
}

override suspend fun broadcastMessage(
Expand Down

0 comments on commit 8d18a4d

Please sign in to comment.