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,27 +174,22 @@ 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
|
Response.Code.TEMPORARY_FAILURE -> "The server encountered a temporary failure."
|
||||||
if (response.code == Response.Code.SLOW_DOWN) {
|
Response.Code.SERVER_UNAVAILABLE -> "The server is currently unavailable."
|
||||||
longMessage =
|
Response.Code.CGI_ERROR -> "A CGI script encountered an error."
|
||||||
"You should wait ${response.meta.toIntOrNull() ?: "a few"} seconds before retrying."
|
Response.Code.PROXY_ERROR -> "The server failed to proxy the request."
|
||||||
} else {
|
Response.Code.SLOW_DOWN -> "You should wait ${response.meta.toIntOrNull() ?: "a few"} seconds before retrying."
|
||||||
longMessage = when (response.code) {
|
Response.Code.PERMANENT_FAILURE -> "This request failed and similar requests will likely fail as well."
|
||||||
Response.Code.TEMPORARY_FAILURE -> "The server encountered a temporary failure."
|
Response.Code.NOT_FOUND -> "This page can't be found."
|
||||||
Response.Code.SERVER_UNAVAILABLE -> "The server is currently unavailable."
|
Response.Code.GONE -> "This page is gone."
|
||||||
Response.Code.CGI_ERROR -> "A CGI script encountered an error."
|
Response.Code.PROXY_REQUEST_REFUSED -> "The server refused to proxy the request."
|
||||||
Response.Code.PROXY_ERROR -> "The server failed to proxy the request."
|
Response.Code.BAD_REQUEST -> "Bad request."
|
||||||
Response.Code.PERMANENT_FAILURE -> "This request failed and similar requests will likely fail as well."
|
else -> "Unknown error code."
|
||||||
Response.Code.NOT_FOUND -> "This page can't be found."
|
|
||||||
Response.Code.GONE -> "This page is gone."
|
|
||||||
Response.Code.PROXY_REQUEST_REFUSED -> "The server refused to proxy the request."
|
|
||||||
Response.Code.BAD_REQUEST -> "Bad request."
|
|
||||||
else -> "Unknown error code."
|
|
||||||
}
|
|
||||||
if (response.meta.isNotEmpty())
|
|
||||||
serverMessage = response.meta
|
|
||||||
}
|
}
|
||||||
|
var serverMessage: String? = null
|
||||||
|
if (response.code != Response.Code.SLOW_DOWN && response.meta.isNotEmpty())
|
||||||
|
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