mirror of
https://github.com/oxen-io/session-android.git
synced 2025-05-01 06:30:48 +00:00
fix error handling
This commit is contained in:
parent
293b01e857
commit
4628f27d9f
@ -76,21 +76,21 @@ object MessageSender {
|
|||||||
// Set the timestamp, sender and recipient
|
// Set the timestamp, sender and recipient
|
||||||
message.sentTimestamp ?: run { message.sentTimestamp = System.currentTimeMillis() } /* Visible messages will already have their sent timestamp set */
|
message.sentTimestamp ?: run { message.sentTimestamp = System.currentTimeMillis() } /* Visible messages will already have their sent timestamp set */
|
||||||
message.sender = userPublicKey
|
message.sender = userPublicKey
|
||||||
|
val isSelfSend = (message.recipient == userPublicKey)
|
||||||
|
// Set the failure handler (need it here already for precondition failure handling)
|
||||||
|
fun handleFailure(error: Exception) {
|
||||||
|
handleFailedMessageSend(message, error)
|
||||||
|
if (destination is Destination.Contact && message is VisibleMessage && !isSelfSend) {
|
||||||
|
SnodeConfiguration.shared.broadcaster.broadcast("messageFailed", message.sentTimestamp!!)
|
||||||
|
}
|
||||||
|
deferred.reject(error)
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
when (destination) {
|
when (destination) {
|
||||||
is Destination.Contact -> message.recipient = destination.publicKey
|
is Destination.Contact -> message.recipient = destination.publicKey
|
||||||
is Destination.ClosedGroup -> message.recipient = destination.groupPublicKey
|
is Destination.ClosedGroup -> message.recipient = destination.groupPublicKey
|
||||||
is Destination.OpenGroup -> throw preconditionFailure
|
is Destination.OpenGroup -> throw preconditionFailure
|
||||||
}
|
}
|
||||||
val isSelfSend = (message.recipient == userPublicKey)
|
|
||||||
// Set the failure handler (need it here already for precondition failure handling)
|
|
||||||
fun handleFailure(error: Exception) {
|
|
||||||
handleFailedMessageSend(message, error)
|
|
||||||
if (destination is Destination.Contact && message is VisibleMessage && !isSelfSend) {
|
|
||||||
SnodeConfiguration.shared.broadcaster.broadcast("messageFailed", message.sentTimestamp!!)
|
|
||||||
}
|
|
||||||
deferred.reject(error)
|
|
||||||
}
|
|
||||||
// Validate the message
|
// Validate the message
|
||||||
if (!message.isValid()) { throw Error.InvalidMessage }
|
if (!message.isValid()) { throw Error.InvalidMessage }
|
||||||
// Stop here if this is a self-send, unless it's:
|
// Stop here if this is a self-send, unless it's:
|
||||||
@ -183,15 +183,14 @@ object MessageSender {
|
|||||||
errorCount += 1
|
errorCount += 1
|
||||||
if (errorCount != promiseCount) { return@fail } // Only error out if all promises failed
|
if (errorCount != promiseCount) { return@fail } // Only error out if all promises failed
|
||||||
handleFailure(it)
|
handleFailure(it)
|
||||||
deferred.reject(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.fail {
|
}.fail {
|
||||||
Log.d("Loki", "Couldn't send message due to error: $it.")
|
Log.d("Loki", "Couldn't send message due to error: $it.")
|
||||||
deferred.reject(it)
|
handleFailure(it)
|
||||||
}
|
}
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
deferred.reject(exception)
|
handleFailure(exception)
|
||||||
}
|
}
|
||||||
return promise
|
return promise
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user