Skip to content

Commit 2e7a7e6

Browse files
committed
refactor: replace onFailure with mapCatching to fix code smell of re-throw inside a side function
1 parent ee95a66 commit 2e7a7e6

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

app/src/main/java/to/bitkit/repositories/BlocktankRepo.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,22 @@ class BlocktankRepo @Inject constructor(
152152

153153
private suspend fun refreshCjitEntries(): List<IcJitEntry> {
154154
repeat(CJIT_REFRESH_ATTEMPTS) { attempt ->
155-
runCatching {
155+
val entries = runCatching {
156156
withTimeout(CJIT_REFRESH_TIMEOUT) {
157157
coreService.blocktank.cjitEntries(refresh = true)
158158
}
159-
}.onSuccess { entries ->
159+
}.mapCatching { entries ->
160160
_blocktankState.update { it.copy(cjitEntries = entries.toImmutableList()) }
161-
return entries
162-
}.onFailure {
161+
entries
162+
}.getOrElse {
163163
if (it is CancellationException && it !is TimeoutCancellationException) throw it
164164
if (attempt == CJIT_REFRESH_ATTEMPTS - 1) {
165165
Logger.warn("Failed to refresh CJIT entries; using cached state", it, context = TAG)
166166
}
167+
null
167168
}
169+
170+
entries?.let { return it }
168171
delay(CJIT_REFRESH_RETRY_DELAY)
169172
}
170173
return _blocktankState.value.cjitEntries

0 commit comments

Comments
 (0)