Unwrap IOException in getReadableString()

This commit is contained in:
FooIbar authored and tarsin committed 2023-07-03 22:55:05 +08:00
1 parent f59789a11e
commit ce888a0982
1 file changed
+10
@@ -19,6 +19,7 @@ import com.hippo.ehviewer.R
import com.hippo.ehviewer.client.exception.EhException
import com.hippo.ehviewer.network.StatusCodeException
import splitties.init.appCtx
import java.io.IOException
import java.net.MalformedURLException
import java.net.ProtocolException
import java.net.SocketException
@@ -29,6 +30,15 @@ import javax.net.ssl.SSLException
object ExceptionUtils {
fun getReadableString(e: Throwable): String {
e.printStackTrace()
val cause = e.cause
return if (e is IOException && cause != null) {
getReadableStringInternal(cause)
} else {
getReadableStringInternal(e)
}
}
private fun getReadableStringInternal(e: Throwable): String {
return when (e) {
is MalformedURLException -> appCtx.getString(R.string.error_invalid_url)
is SocketTimeoutException -> appCtx.getString(R.string.error_timeout)