make error description show in the message detail activity

This commit is contained in:
Ryan ZHAO
2021-03-16 16:31:52 +11:00
parent 2e65077b3a
commit 95646ed04e
9 changed files with 20 additions and 16 deletions

View File

@@ -17,7 +17,7 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long)
private val MAX_ATTACHMENT_SIZE = 10 * 1024 * 1024
// Error
internal sealed class Error(val description: String) : Exception() {
internal sealed class Error(val description: String) : Exception(description) {
object NoAttachment : Error("No such attachment.")
}

View File

@@ -25,7 +25,7 @@ class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val mess
override var failureCount: Int = 0
// Error
internal sealed class Error(val description: String) : Exception() {
internal sealed class Error(val description: String) : Exception(description) {
object NoAttachment : Error("No such attachment.")
}

View File

@@ -11,7 +11,7 @@ object MessageReceiver {
private val lastEncryptionKeyPairRequest = mutableMapOf<String, Long>()
internal sealed class Error(val description: String) : Exception() {
internal sealed class Error(val description: String) : Exception(description) {
object DuplicateMessage: Error("Duplicate message.")
object InvalidMessage: Error("Invalid message.")
object UnknownMessage: Error("Unknown message type.")

View File

@@ -34,7 +34,7 @@ import org.session.libsignal.utilities.logging.Log
object MessageSender {
// Error
sealed class Error(val description: String) : Exception() {
sealed class Error(val description: String) : Exception(description) {
object InvalidMessage : Error("Invalid message.")
object ProtoConversionFailed : Error("Couldn't convert message to proto.")
object ProofOfWorkCalculationFailed : Error("Proof of work calculation failed.")
@@ -202,6 +202,11 @@ object MessageSender {
val preconditionFailure = Exception("Destination should not be contacts or closed groups!")
message.sentTimestamp ?: run { message.sentTimestamp = System.currentTimeMillis() }
message.sender = storage.getUserPublicKey()
// Set the failure handler (need it here already for precondition failure handling)
fun handleFailure(error: Exception) {
handleFailedMessageSend(message, error)
deferred.reject(error)
}
try {
val server: String
val channel: Long
@@ -214,19 +219,12 @@ object MessageSender {
channel = destination.channel
}
}
// Set the failure handler (need it here already for precondition failure handling)
fun handleFailure(error: Exception) {
handleFailedMessageSend(message, error)
deferred.reject(error)
}
// Validate the message
if (message !is VisibleMessage || !message.isValid()) {
handleFailure(Error.InvalidMessage)
throw Error.InvalidMessage
}
// Convert the message to an open group message
val openGroupMessage = OpenGroupMessage.from(message, server) ?: kotlin.run {
handleFailure(Error.InvalidMessage)
throw Error.InvalidMessage
}
// Send the result
@@ -238,7 +236,7 @@ object MessageSender {
handleFailure(it)
}
} catch (exception: Exception) {
deferred.reject(exception)
handleFailure(exception)
}
return deferred.promise
}

View File

@@ -42,7 +42,7 @@ open class DotNetAPI {
internal enum class HTTPVerb { GET, PUT, POST, DELETE, PATCH }
// Error
internal sealed class Error(val description: String) : Exception() {
internal sealed class Error(val description: String) : Exception(description) {
object Generic : Error("An error occurred.")
object InvalidURL : Error("Invalid URL.")
object ParsingFailed : Error("Invalid file server response.")

View File

@@ -10,7 +10,7 @@ import java.security.SecureRandom
object MessageWrapper {
// region Types
sealed class Error(val description: String) : Exception() {
sealed class Error(val description: String) : Exception(description) {
object FailedToWrapData : Error("Failed to wrap data.")
object FailedToWrapMessageInEnvelope : Error("Failed to wrap message in envelope.")
object FailedToWrapEnvelopeInWebSocketMessage : Error("Failed to wrap envelope in web socket message.")

View File

@@ -45,7 +45,7 @@ object SnodeAPI {
internal var powDifficulty = 1
// Error
internal sealed class Error(val description: String) : Exception() {
internal sealed class Error(val description: String) : Exception(description) {
object Generic : Error("An error occurred.")
object ClockOutOfSync : Error("The user's clock is out of sync with the service node network.")
object RandomSnodePoolUpdatingFailed : Error("Failed to update random service node pool.")