1
0
Fork 0
mirror of https://github.com/Corewala/Buran synced 2024-12-22 07:42:43 +00:00

Fixed mystery connection error (for real this time)

Again, kind of an ugly fix, but at least it works I think
This commit is contained in:
Corewala 2022-05-26 14:05:58 -04:00
parent 589ab24a7e
commit 30dcb45661
3 changed files with 10 additions and 8 deletions

View file

@ -15,7 +15,7 @@ sealed class GemState {
data class ResponseImage(val uri: URI, val header: GeminiResponse.Header, val cacheUri: Uri) : GemState()
data class ResponseBinary(val uri: URI, val header: GeminiResponse.Header, val cacheUri: Uri) : GemState()
data class ResponseUnknownMime(val uri: URI, val header: GeminiResponse.Header) : GemState()
data class ResponseError(val header: GeminiResponse.Header): GemState()
data class ResponseError(val uri: URI, val header: GeminiResponse.Header): GemState()
data class ResponseUnknownHost(val uri: URI): GemState()
data class ClientCertRequired(val uri: URI, val header: GeminiResponse.Header): GemState()
data class ClientCertError(val header: GeminiResponse.Header): GemState()

View file

@ -71,11 +71,11 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
return
}catch (ce: ConnectException){
println("Buran socket error, connect exception: $ce")
onUpdate(GemState.ResponseError(GeminiResponse.Header(-1, ce.message ?: ce.toString())))
onUpdate(GemState.ResponseError(uri, GeminiResponse.Header(-1, ce.message ?: ce.toString())))
return
}catch (she: SSLHandshakeException){
println("Buran socket error, ssl handshake exception: $she")
onUpdate(GemState.ResponseError(GeminiResponse.Header(-2, she.message ?: she.toString())))
onUpdate(GemState.ResponseError(uri, GeminiResponse.Header(-2, she.message ?: she.toString())))
return
}
@ -90,7 +90,7 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
outWriter.flush()
if (outWriter.checkError()) {
onUpdate(GemState.ResponseError(GeminiResponse.Header(-1, "Print Writer Error")))
onUpdate(GemState.ResponseError(uri, GeminiResponse.Header(-1, "Print Writer Error")))
outWriter.close()
return
}
@ -105,7 +105,7 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
println("Buran: response header: $headerLine")
if(headerLine == null){
onUpdate(GemState.ResponseError(GeminiResponse.Header(-2, "Server did not respond with a Gemini header: $uri")))
onUpdate(GemState.ResponseError(uri, GeminiResponse.Header(-2, "Server did not respond with a Gemini header: $uri")))
return
}
@ -115,7 +115,7 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
header.code == GeminiResponse.INPUT -> onUpdate(GemState.ResponseInput(uri, header))
header.code == GeminiResponse.REDIRECT -> onUpdate(GemState.Redirect(resolve(uri.host, header.meta)))
header.code == GeminiResponse.CLIENT_CERTIFICATE_REQUIRED -> onUpdate(GemState.ClientCertRequired(uri, header))
header.code != GeminiResponse.SUCCESS -> onUpdate(GemState.ResponseError(header))
header.code != GeminiResponse.SUCCESS -> onUpdate(GemState.ResponseError(uri, header))
header.meta.startsWith("text/gemini") -> getGemtext(bufferedReader, uri, header, onUpdate)
header.meta.startsWith("text/") -> getString(socket, uri, header, onUpdate)
header.meta.startsWith("image/") -> getBinary(socket, uri, header, onUpdate)

View file

@ -483,8 +483,10 @@ class GemActivity : AppCompatActivity() {
is GemState.Requesting -> loadingView(true)
is GemState.NotGeminiRequest -> externalProtocol(state)
is GemState.ResponseError -> {
omniTerm.reset()
showAlert("${GeminiResponse.getCodeString(state.header.code)}:\n\n${state.header.meta}")
if(omniTerm.canGoBack() or (prefs.getString("home_capsule", Buran.DEFAULT_HOME_CAPSULE) == state.uri.toString())){
omniTerm.reset()
showAlert("${GeminiResponse.getCodeString(state.header.code)}:\n\n${state.header.meta}")
}
}
is GemState.ClientCertError -> {
certPassword = null