Skip to content

Commit

Permalink
chore: add error log for long storage requests [#WPB-11603]
Browse files Browse the repository at this point in the history
  • Loading branch information
sbakhtiarov committed Jan 13, 2025
1 parent d54cc28 commit 140fe4d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlin.time.measureTime

sealed interface CoreFailure {

Expand Down Expand Up @@ -371,12 +372,20 @@ internal inline fun <T> wrapE2EIRequest(e2eiRequest: () -> T): Either<E2EIFailur
}

internal inline fun <T : Any> wrapStorageRequest(storageRequest: () -> T?): Either<StorageFailure, T> {
val result = try {
storageRequest()?.let { data -> Either.Right(data) } ?: Either.Left(StorageFailure.DataNotFound)
} catch (e: Exception) {
Either.Left(StorageFailure.Generic(e))
val result: Either<StorageFailure, T>
measureTime {
result = try {
storageRequest()?.let { data -> Either.Right(data) } ?: Either.Left(StorageFailure.DataNotFound)
} catch (e: Exception) {
Either.Left(StorageFailure.Generic(e))
}
result.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) }
}.run {
// Log error for requests longer than 1 second
if (inWholeSeconds > 1) {
kaliumLogger.e("storage request timeMs: $inWholeMilliseconds")
}
}
result.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) }
return result
}

Expand Down

0 comments on commit 140fe4d

Please sign in to comment.