diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 2e8279e16..795cc80ae 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -458,7 +458,8 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc func showFailedMessageSheet(for tsMessage: TSOutgoingMessage) { let thread = self.thread - let sheet = UIAlertController(title: tsMessage.mostRecentFailureText, message: nil, preferredStyle: .actionSheet) + let error = tsMessage.mostRecentFailureText + let sheet = UIAlertController(title: error, message: nil, preferredStyle: .actionSheet) sheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) sheet.addAction(UIAlertAction(title: "Delete", style: .destructive, handler: { _ in Storage.write { transaction in @@ -480,6 +481,17 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc MessageSender.send(message, in: thread, using: transaction) } })) + // HACK: Extracting this info from the error string is pretty dodgy + let prefix = "HTTP request failed at destination (Service node " + if error.hasPrefix(prefix) { + let rest = error.substring(from: prefix.count) + if let index = rest.firstIndex(of: ")") { + let snodeAddress = String(rest[rest.startIndex.. Promise { let payload: JSON = [ "method" : method.rawValue, "params" : parameters ] return sendOnionRequest(with: payload, to: Destination.snode(snode)).recover2 { error -> Promise in - guard case OnionRequestAPI.Error.httpRequestFailedAtDestination(let statusCode, let json) = error else { throw error } + guard case OnionRequestAPI.Error.httpRequestFailedAtDestination(let statusCode, let json, _) = error else { throw error } throw SnodeAPI.handleError(withStatusCode: statusCode, json: json, forSnode: snode, associatedWith: publicKey) ?? error } } @@ -397,10 +404,10 @@ public enum OnionRequestAPI { let b = try JSONSerialization.jsonObject(with: bodyAsData, options: [ .fragmentsAllowed ]) as? JSON else { return seal.reject(HTTP.Error.invalidJSON) } body = b } - guard 200...299 ~= statusCode else { return seal.reject(Error.httpRequestFailedAtDestination(statusCode: UInt(statusCode), json: body)) } + guard 200...299 ~= statusCode else { return seal.reject(Error.httpRequestFailedAtDestination(statusCode: UInt(statusCode), json: body, destination: destination)) } seal.fulfill(body) } else { - guard 200...299 ~= statusCode else { return seal.reject(Error.httpRequestFailedAtDestination(statusCode: UInt(statusCode), json: json)) } + guard 200...299 ~= statusCode else { return seal.reject(Error.httpRequestFailedAtDestination(statusCode: UInt(statusCode), json: json, destination: destination)) } seal.fulfill(json) } } catch {