Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Result with exception handling #906

Merged
merged 7 commits into from
Feb 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Slight tidy up
  • Loading branch information
dturner committed Feb 24, 2023
commit 49a48eefff6a1362c60edebb7185e72d520d3533
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TaskDetailViewModel @Inject constructor(
private val _isLoading = MutableStateFlow(false)
private val _isTaskDeleted = MutableStateFlow(false)
private val _taskAsync = tasksRepository.getTaskStream(taskId)
.map { handleResult(it) }
.map { handleTask(it) }
.catch { emit(Async.Error(R.string.loading_task_error)) }

val uiState: StateFlow<TaskDetailUiState> = combine(
Expand Down Expand Up @@ -124,10 +124,10 @@ class TaskDetailViewModel @Inject constructor(
_userMessage.value = message
}

private fun handleResult(tasksResult: Task?): Async<Task?> =
if (tasksResult != null) {
Async.Success(tasksResult)
} else {
private fun handleTask(task: Task?): Async<Task?> =
if (task == null) {
Async.Error(R.string.task_not_found)
} else {
Async.Success(task)
}
}