mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-21 10:28:27 +00:00
Include destination info in error messages
This commit is contained in:
parent
e7bf27671d
commit
5b612806c5
@ -86,6 +86,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
|
android:textIsSelectable="true"
|
||||||
tools:text="Send Failed"/>
|
tools:text="Send Failed"/>
|
||||||
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
@ -70,19 +70,19 @@ object OnionRequestAPI {
|
|||||||
const val targetPathCount = 2 // A main path and a backup path for the case where the target snode is in the main path
|
const val targetPathCount = 2 // A main path and a backup path for the case where the target snode is in the main path
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
class HTTPRequestFailedAtDestinationException(val statusCode: Int, val json: Map<*, *>)
|
class HTTPRequestFailedAtDestinationException(val statusCode: Int, val json: Map<*, *>, val destination: String)
|
||||||
: Exception("HTTP request failed at destination with status code $statusCode.")
|
: Exception("HTTP request failed at destination ($destination) with status code $statusCode.")
|
||||||
class InsufficientSnodesException : Exception("Couldn't find enough snodes to build a path.")
|
class InsufficientSnodesException : Exception("Couldn't find enough snodes to build a path.")
|
||||||
|
|
||||||
private data class OnionBuildingResult(
|
private data class OnionBuildingResult(
|
||||||
val guardSnode: Snode,
|
val guardSnode: Snode,
|
||||||
val finalEncryptionResult: EncryptionResult,
|
val finalEncryptionResult: EncryptionResult,
|
||||||
val destinationSymmetricKey: ByteArray
|
val destinationSymmetricKey: ByteArray
|
||||||
)
|
)
|
||||||
|
|
||||||
internal sealed class Destination {
|
internal sealed class Destination(val description: String) {
|
||||||
class Snode(val snode: org.session.libsignal.utilities.Snode) : Destination()
|
class Snode(val snode: org.session.libsignal.utilities.Snode) : Destination("Service node ${snode.ip}:${snode.port}")
|
||||||
class Server(val host: String, val target: String, val x25519PublicKey: String, val scheme: String, val port: Int) : Destination()
|
class Server(val host: String, val target: String, val x25519PublicKey: String, val scheme: String, val port: Int) : Destination("$host")
|
||||||
}
|
}
|
||||||
|
|
||||||
// region Private API
|
// region Private API
|
||||||
@ -339,7 +339,7 @@ object OnionRequestAPI {
|
|||||||
val statusCode = json["status_code"] as? Int ?: json["status"] as Int
|
val statusCode = json["status_code"] as? Int ?: json["status"] as Int
|
||||||
if (statusCode == 406) {
|
if (statusCode == 406) {
|
||||||
@Suppress("NAME_SHADOWING") val body = mapOf( "result" to "Your clock is out of sync with the service node network." )
|
@Suppress("NAME_SHADOWING") val body = mapOf( "result" to "Your clock is out of sync with the service node network." )
|
||||||
val exception = HTTPRequestFailedAtDestinationException(statusCode, body)
|
val exception = HTTPRequestFailedAtDestinationException(statusCode, body, destination.description)
|
||||||
return@queue deferred.reject(exception)
|
return@queue deferred.reject(exception)
|
||||||
} else if (json["body"] != null) {
|
} else if (json["body"] != null) {
|
||||||
@Suppress("NAME_SHADOWING") val body: Map<*, *>
|
@Suppress("NAME_SHADOWING") val body: Map<*, *>
|
||||||
@ -354,13 +354,13 @@ object OnionRequestAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (statusCode != 200) {
|
if (statusCode != 200) {
|
||||||
val exception = HTTPRequestFailedAtDestinationException(statusCode, body)
|
val exception = HTTPRequestFailedAtDestinationException(statusCode, body, destination.description)
|
||||||
return@queue deferred.reject(exception)
|
return@queue deferred.reject(exception)
|
||||||
}
|
}
|
||||||
deferred.resolve(body)
|
deferred.resolve(body)
|
||||||
} else {
|
} else {
|
||||||
if (statusCode != 200) {
|
if (statusCode != 200) {
|
||||||
val exception = HTTPRequestFailedAtDestinationException(statusCode, json)
|
val exception = HTTPRequestFailedAtDestinationException(statusCode, json, destination.description)
|
||||||
return@queue deferred.reject(exception)
|
return@queue deferred.reject(exception)
|
||||||
}
|
}
|
||||||
deferred.resolve(json)
|
deferred.resolve(json)
|
||||||
|
@ -101,12 +101,12 @@ object SnodeAPI {
|
|||||||
val url = "$target/json_rpc"
|
val url = "$target/json_rpc"
|
||||||
Log.d("Loki", "Populating snode pool using: $target.")
|
Log.d("Loki", "Populating snode pool using: $target.")
|
||||||
val parameters = mapOf(
|
val parameters = mapOf(
|
||||||
"method" to "get_n_service_nodes",
|
"method" to "get_n_service_nodes",
|
||||||
"params" to mapOf(
|
"params" to mapOf(
|
||||||
"active_only" to true,
|
"active_only" to true,
|
||||||
"limit" to 256,
|
"limit" to 256,
|
||||||
"fields" to mapOf("public_ip" to true, "storage_port" to true, "pubkey_x25519" to true, "pubkey_ed25519" to true)
|
"fields" to mapOf("public_ip" to true, "storage_port" to true, "pubkey_x25519" to true, "pubkey_ed25519" to true)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val deferred = deferred<Snode, Exception>()
|
val deferred = deferred<Snode, Exception>()
|
||||||
deferred<Snode, Exception>()
|
deferred<Snode, Exception>()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user