BugFix Crashing relay screen on invalid URLs

This commit is contained in:
Vitor Pamplona
2023-06-30 08:58:14 -04:00
parent 3908c42c7f
commit b820b6564f

View File

@@ -292,6 +292,7 @@ fun loadRelayInfo(
scope: CoroutineScope, scope: CoroutineScope,
onInfo: (RelayInformation) -> Unit onInfo: (RelayInformation) -> Unit
) { ) {
try {
val url = if (dirtyUrl.contains("://")) { val url = if (dirtyUrl.contains("://")) {
dirtyUrl dirtyUrl
.replace("wss://", "https://") .replace("wss://", "https://")
@@ -328,7 +329,7 @@ fun loadRelayInfo(
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.e("RelayInfoFail", "Resulting Message from Relay in not parseable: $body", e) Log.e("RelayInfoFail", "Resulting Message from Relay $dirtyUrl in not parseable: $body", e)
scope.launch { scope.launch {
Toast Toast
.makeText( .makeText(
@@ -342,7 +343,7 @@ fun loadRelayInfo(
} }
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
Log.e("RelayInfoFail", "Resulting Message from Relay in not parseable", e) Log.e("RelayInfoFail", "Resulting Message from Relay in not parseable $dirtyUrl", e)
scope.launch { scope.launch {
Toast Toast
.makeText( .makeText(
@@ -354,4 +355,15 @@ fun loadRelayInfo(
} }
} }
) )
} catch (e: Exception) {
Log.e("RelayInfoFail", "Invalid URL $dirtyUrl", e)
scope.launch {
Toast
.makeText(
context,
context.getString(R.string.an_error_ocurred_trying_to_get_relay_information, dirtyUrl),
Toast.LENGTH_SHORT
).show()
}
}
} }