mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Simplify JobCancellationException
This commit is contained in:
parent
af99390643
commit
c59637f7ec
@ -84,17 +84,21 @@ class NewMessageViewModel @Inject constructor(
|
||||
_state.update { it.copy(loading = false) }
|
||||
onPublicKey(onsNameOrPublicKey)
|
||||
}
|
||||
} catch (e: CancellationException) {
|
||||
if (e is TimeoutCancellationException) {
|
||||
// Ignore JobCancellationException, which is called when we cancel the job.
|
||||
onError(e)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// JobCancellationException is thrown if we cancel the job
|
||||
// but it is internal, so this excludes other subclasses of CancellationException
|
||||
// than TimeoutCancellationException
|
||||
if (e is TimeoutCancellationException == e is CancellationException) {
|
||||
onError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onError(e: Exception) {
|
||||
_state.update { it.copy(loading = false, error = GetString(e) { it.toMessage() }) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onPublicKey(onsNameOrPublicKey: String) {
|
||||
viewModelScope.launch { _event.send(Event.Success(onsNameOrPublicKey)) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user