@ -41,11 +41,13 @@ import org.koitharu.kotatsu.scrobbling.common.domain.ScrobblerAuthRequiredExcept
import java.io.ObjectOutputStream
import java.io.ObjectOutputStream
import java.net.ConnectException
import java.net.ConnectException
import java.net.NoRouteToHostException
import java.net.NoRouteToHostException
import java.net.SocketException
import java.net.SocketTimeoutException
import java.net.SocketTimeoutException
import java.net.UnknownHostException
import java.net.UnknownHostException
import java.util.Locale
import java.util.Locale
private const val MSG _NO _SPACE _LEFT = " No space left on device "
private const val MSG _NO _SPACE _LEFT = " No space left on device "
private const val MSG _CONNECTION _RESET = " Connection reset "
private const val IMAGE _FORMAT _NOT _SUPPORTED = " Image format not supported "
private const val IMAGE _FORMAT _NOT _SUPPORTED = " Image format not supported "
fun Throwable . getDisplayMessage ( resources : Resources ) : String = getDisplayMessageOrNull ( resources )
fun Throwable . getDisplayMessage ( resources : Resources ) : String = getDisplayMessageOrNull ( resources )
@ -117,7 +119,7 @@ private fun Throwable.getDisplayMessageOrNull(resources: Resources): String? = w
is HttpException -> getHttpDisplayMessage ( response . code , resources )
is HttpException -> getHttpDisplayMessage ( response . code , resources )
is HttpStatusException -> getHttpDisplayMessage ( statusCode , resources )
is HttpStatusException -> getHttpDisplayMessage ( statusCode , resources )
else -> get DisplayMessage( message , resources ) ?: message
else -> map DisplayMessage( message , resources ) ?: message
} . takeUnless { it . isNullOrBlank ( ) }
} . takeUnless { it . isNullOrBlank ( ) }
@DrawableRes
@DrawableRes
@ -154,10 +156,11 @@ private fun getHttpDisplayMessage(statusCode: Int, resources: Resources): String
else -> null
else -> null
}
}
private fun get DisplayMessage( msg : String ? , resources : Resources ) : String ? = when {
private fun map DisplayMessage( msg : String ? , resources : Resources ) : String ? = when {
msg . isNullOrEmpty ( ) -> null
msg . isNullOrEmpty ( ) -> null
msg . contains ( MSG _NO _SPACE _LEFT ) -> resources . getString ( R . string . error _no _space _left )
msg . contains ( MSG _NO _SPACE _LEFT ) -> resources . getString ( R . string . error _no _space _left )
msg . contains ( IMAGE _FORMAT _NOT _SUPPORTED ) -> resources . getString ( R . string . error _corrupted _file )
msg . contains ( IMAGE _FORMAT _NOT _SUPPORTED ) -> resources . getString ( R . string . error _corrupted _file )
msg == MSG _CONNECTION _RESET -> resources . getString ( R . string . error _connection _reset )
msg == FILTER _MULTIPLE _GENRES _NOT _SUPPORTED -> resources . getString ( R . string . error _multiple _genres _not _supported )
msg == FILTER _MULTIPLE _GENRES _NOT _SUPPORTED -> resources . getString ( R . string . error _multiple _genres _not _supported )
msg == FILTER _MULTIPLE _STATES _NOT _SUPPORTED -> resources . getString ( R . string . error _multiple _states _not _supported )
msg == FILTER _MULTIPLE _STATES _NOT _SUPPORTED -> resources . getString ( R . string . error _multiple _states _not _supported )
msg == SEARCH _NOT _SUPPORTED -> resources . getString ( R . string . error _search _not _supported )
msg == SEARCH _NOT _SUPPORTED -> resources . getString ( R . string . error _search _not _supported )
@ -184,6 +187,7 @@ fun Throwable.isReportable(): Boolean {
|| this is WrongPasswordException
|| this is WrongPasswordException
|| this is TooManyRequestExceptions
|| this is TooManyRequestExceptions
|| this is HttpStatusException
|| this is HttpStatusException
|| this is SocketException
) {
) {
return false
return false
}
}