Catch error and return Result in useCases

This commit is contained in:
Florian Renaud 2022-10-05 00:28:42 +02:00
parent 30f33d36de
commit b286a52f5b
4 changed files with 8 additions and 8 deletions

View File

@ -33,8 +33,8 @@ class PauseVoiceBroadcastUseCase @Inject constructor(
private val session: Session,
) {
suspend fun execute(roomId: String) {
val room = session.getRoom(roomId) ?: return
suspend fun execute(roomId: String): Result<Unit> = runCatching {
val room = session.getRoom(roomId) ?: error("Unknown roomId: $roomId")
Timber.d("## PauseVoiceBroadcastUseCase: Pause voice broadcast requested")

View File

@ -33,8 +33,8 @@ class ResumeVoiceBroadcastUseCase @Inject constructor(
private val session: Session,
) {
suspend fun execute(roomId: String) {
val room = session.getRoom(roomId) ?: return
suspend fun execute(roomId: String): Result<Unit> = runCatching {
val room = session.getRoom(roomId) ?: error("Unknown roomId: $roomId")
Timber.d("## ResumeVoiceBroadcastUseCase: Resume voice broadcast requested")

View File

@ -32,8 +32,8 @@ class StartVoiceBroadcastUseCase @Inject constructor(
private val session: Session,
) {
suspend fun execute(roomId: String) {
val room = session.getRoom(roomId) ?: return
suspend fun execute(roomId: String): Result<Unit> = runCatching {
val room = session.getRoom(roomId) ?: error("Unknown roomId: $roomId")
Timber.d("## StartVoiceBroadcastUseCase: Start voice broadcast requested")

View File

@ -33,8 +33,8 @@ class StopVoiceBroadcastUseCase @Inject constructor(
private val session: Session,
) {
suspend fun execute(roomId: String) {
val room = session.getRoom(roomId) ?: return
suspend fun execute(roomId: String): Result<Unit> = runCatching {
val room = session.getRoom(roomId) ?: error("Unknown roomId: $roomId")
Timber.d("## StopVoiceBroadcastUseCase: Stop voice broadcast requested")