Use more concise runCatching instead of Result
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user