Use more concise runCatching instead of Result

This commit is contained in:
Kirill Kamakin
2021-11-13 10:14:15 +03:00
parent 10b3dadc3d
commit cb495aaba3
6 changed files with 19 additions and 25 deletions

View File

@@ -71,8 +71,13 @@ class AuthenticationFragment : Fragment() {
} ?: return
}
lifecycleScope.launchWhenResumed {
val exception = viewModel.authenticate(email, pass, url)
if (exception == null) navigateToRecipes()
runCatching {
viewModel.authenticate(email, pass, url)
}.onSuccess {
navigateToRecipes()
}.onFailure {
Timber.e(it, "Can't authenticate")
}
}
}

View File

@@ -21,11 +21,8 @@ class AuthenticationViewModel @Inject constructor(
return result
}
suspend fun authenticate(username: String, password: String, baseUrl: String): Throwable? {
suspend fun authenticate(username: String, password: String, baseUrl: String) {
Timber.v("authenticate() called with: username = $username, password = $password, baseUrl = $baseUrl")
val result = authRepo.authenticate(username, password, baseUrl)
if (result == null) Timber.d("authenticate() returns null")
else Timber.e(result, "authenticate() returns error")
return result
authRepo.authenticate(username, password, baseUrl)
}
}