Request: catch SSLProtocolException
For some reason this does not make the whole page reception to fail. User is not warned about this exception, which may or may not be bad.
This commit is contained in:
parent
4282567f5f
commit
a822287de2
|
@ -120,7 +120,7 @@ class PageViewModel(@Suppress("unused") private val savedStateHandle: SavedState
|
||||||
var mainTitle: String? = null
|
var mainTitle: String? = null
|
||||||
var lastUpdate = System.currentTimeMillis()
|
var lastUpdate = System.currentTimeMillis()
|
||||||
var lastNumLines = 0
|
var lastNumLines = 0
|
||||||
Log.d(TAG, "handleRequestSuccess: start parsing line data")
|
Log.d(TAG, "handleSuccessResponse: start parsing line data")
|
||||||
try {
|
try {
|
||||||
val lineChannel = parseData(response.data, charset, viewModelScope)
|
val lineChannel = parseData(response.data, charset, viewModelScope)
|
||||||
while (!lineChannel.isClosedForReceive) {
|
while (!lineChannel.isClosedForReceive) {
|
||||||
|
@ -142,11 +142,11 @@ class PageViewModel(@Suppress("unused") private val savedStateHandle: SavedState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: CancellationException) {
|
} catch (e: CancellationException) {
|
||||||
Log.e(TAG, "handleRequestSuccess: coroutine cancelled: ${e.message}")
|
Log.e(TAG, "handleSuccessResponse: coroutine cancelled: ${e.message}")
|
||||||
state.postValue(State.IDLE)
|
state.postValue(State.IDLE)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Log.d(TAG, "handleRequestSuccess: done parsing line data")
|
Log.d(TAG, "handleSuccessResponse: done parsing line data")
|
||||||
lines.postValue(linesList)
|
lines.postValue(linesList)
|
||||||
|
|
||||||
// We record the history entry here: it's nice because we have the main title available
|
// We record the history entry here: it's nice because we have the main title available
|
||||||
|
@ -174,17 +174,12 @@ class PageViewModel(@Suppress("unused") private val savedStateHandle: SavedState
|
||||||
Response.Code.BAD_REQUEST -> "59 Bad request"
|
Response.Code.BAD_REQUEST -> "59 Bad request"
|
||||||
else -> "${response.code} (unknown)"
|
else -> "${response.code} (unknown)"
|
||||||
}
|
}
|
||||||
val longMessage: String
|
val longMessage: String = when (response.code) {
|
||||||
var serverMessage: String? = null
|
|
||||||
if (response.code == Response.Code.SLOW_DOWN) {
|
|
||||||
longMessage =
|
|
||||||
"You should wait ${response.meta.toIntOrNull() ?: "a few"} seconds before retrying."
|
|
||||||
} else {
|
|
||||||
longMessage = when (response.code) {
|
|
||||||
Response.Code.TEMPORARY_FAILURE -> "The server encountered a temporary failure."
|
Response.Code.TEMPORARY_FAILURE -> "The server encountered a temporary failure."
|
||||||
Response.Code.SERVER_UNAVAILABLE -> "The server is currently unavailable."
|
Response.Code.SERVER_UNAVAILABLE -> "The server is currently unavailable."
|
||||||
Response.Code.CGI_ERROR -> "A CGI script encountered an error."
|
Response.Code.CGI_ERROR -> "A CGI script encountered an error."
|
||||||
Response.Code.PROXY_ERROR -> "The server failed to proxy the request."
|
Response.Code.PROXY_ERROR -> "The server failed to proxy the request."
|
||||||
|
Response.Code.SLOW_DOWN -> "You should wait ${response.meta.toIntOrNull() ?: "a few"} seconds before retrying."
|
||||||
Response.Code.PERMANENT_FAILURE -> "This request failed and similar requests will likely fail as well."
|
Response.Code.PERMANENT_FAILURE -> "This request failed and similar requests will likely fail as well."
|
||||||
Response.Code.NOT_FOUND -> "This page can't be found."
|
Response.Code.NOT_FOUND -> "This page can't be found."
|
||||||
Response.Code.GONE -> "This page is gone."
|
Response.Code.GONE -> "This page is gone."
|
||||||
|
@ -192,9 +187,9 @@ class PageViewModel(@Suppress("unused") private val savedStateHandle: SavedState
|
||||||
Response.Code.BAD_REQUEST -> "Bad request."
|
Response.Code.BAD_REQUEST -> "Bad request."
|
||||||
else -> "Unknown error code."
|
else -> "Unknown error code."
|
||||||
}
|
}
|
||||||
if (response.meta.isNotEmpty())
|
var serverMessage: String? = null
|
||||||
|
if (response.code != Response.Code.SLOW_DOWN && response.meta.isNotEmpty())
|
||||||
serverMessage = response.meta
|
serverMessage = response.meta
|
||||||
}
|
|
||||||
event.postValue(FailureEvent(briefMessage, longMessage, serverMessage))
|
event.postValue(FailureEvent(briefMessage, longMessage, serverMessage))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.net.InetSocketAddress
|
||||||
import java.net.SocketTimeoutException
|
import java.net.SocketTimeoutException
|
||||||
import java.security.cert.X509Certificate
|
import java.security.cert.X509Certificate
|
||||||
import javax.net.ssl.SSLContext
|
import javax.net.ssl.SSLContext
|
||||||
|
import javax.net.ssl.SSLProtocolException
|
||||||
import javax.net.ssl.SSLSocket
|
import javax.net.ssl.SSLSocket
|
||||||
import javax.net.ssl.X509TrustManager
|
import javax.net.ssl.X509TrustManager
|
||||||
|
|
||||||
|
@ -46,6 +47,8 @@ class Request(private val uri: Uri) {
|
||||||
}
|
}
|
||||||
} catch (e: SocketTimeoutException) {
|
} catch (e: SocketTimeoutException) {
|
||||||
Log.i(TAG, "proceed coroutine: socket timeout.")
|
Log.i(TAG, "proceed coroutine: socket timeout.")
|
||||||
|
} catch (e: SSLProtocolException) {
|
||||||
|
Log.e(TAG, "proceed coroutine: SSL protocol exception: ${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue