ErrorFormatter: create interface
This commit is contained in:
parent
6e4830e325
commit
92e60c939d
@ -26,6 +26,8 @@ import dagger.Provides
|
||||
import im.vector.matrix.android.api.Matrix
|
||||
import im.vector.matrix.android.api.auth.AuthenticationService
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.riotx.core.error.DefaultErrorFormatter
|
||||
import im.vector.riotx.core.error.ErrorFormatter
|
||||
import im.vector.riotx.features.navigation.DefaultNavigator
|
||||
import im.vector.riotx.features.navigation.Navigator
|
||||
import im.vector.riotx.features.ui.SharedPreferencesUiStateRepository
|
||||
@ -72,6 +74,9 @@ abstract class VectorModule {
|
||||
@Binds
|
||||
abstract fun bindNavigator(navigator: DefaultNavigator): Navigator
|
||||
|
||||
@Binds
|
||||
abstract fun bindErrorFormatter(errorFormatter: DefaultErrorFormatter): ErrorFormatter
|
||||
|
||||
@Binds
|
||||
abstract fun bindUiStateRepository(uiStateRepository: SharedPreferencesUiStateRepository): UiStateRepository
|
||||
}
|
||||
|
@ -25,14 +25,15 @@ import java.net.SocketTimeoutException
|
||||
import java.net.UnknownHostException
|
||||
import javax.inject.Inject
|
||||
|
||||
class ErrorFormatter @Inject constructor(private val stringProvider: StringProvider) {
|
||||
interface ErrorFormatter {
|
||||
fun toHumanReadable(throwable: Throwable?): String
|
||||
}
|
||||
|
||||
fun toHumanReadable(failure: Failure): String {
|
||||
// Default
|
||||
return failure.localizedMessage
|
||||
}
|
||||
class DefaultErrorFormatter @Inject constructor(
|
||||
private val stringProvider: StringProvider
|
||||
) : ErrorFormatter {
|
||||
|
||||
fun toHumanReadable(throwable: Throwable?): String {
|
||||
override fun toHumanReadable(throwable: Throwable?): String {
|
||||
return when (throwable) {
|
||||
null -> null
|
||||
is Failure.NetworkConnection -> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user