aboutsummaryrefslogtreecommitdiff
path: root/Hotline
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2024-07-26 16:26:04 -0700
committerDustin Mierau <dustin@mierau.me>2024-07-26 16:26:04 -0700
commitea7d65f60b6a984c15f55fe0a0a3145fbe3d7cbb (patch)
treeb64219f48ff45ab74ed5bc9e52ac1b3449095f45 /Hotline
parent5a1aac0219febaaab953ce354bd75907b22daba5 (diff)
Display error messages from the server.
Diffstat (limited to 'Hotline')
-rw-r--r--Hotline/Hotline/HotlineClient.swift6
-rw-r--r--Hotline/Models/Hotline.swift7
-rw-r--r--Hotline/macOS/ServerView.swift3
3 files changed, 13 insertions, 3 deletions
diff --git a/Hotline/Hotline/HotlineClient.swift b/Hotline/Hotline/HotlineClient.swift
index d31aa96..a151357 100644
--- a/Hotline/Hotline/HotlineClient.swift
+++ b/Hotline/Hotline/HotlineClient.swift
@@ -35,6 +35,7 @@ protocol HotlineClientDelegate: AnyObject {
func hotlineGetUserInfo() -> (String, UInt16)
func hotlineStatusChanged(status: HotlineClientStatus)
func hotlineReceivedAgreement(text: String)
+ func hotlineReceivedErrorMessage(code: UInt32, message: String?)
func hotlineReceivedChatMessage(message: String)
func hotlineReceivedUserList(users: [HotlineUser])
func hotlineReceivedServerMessage(message: String)
@@ -48,6 +49,7 @@ protocol HotlineClientDelegate: AnyObject {
extension HotlineClientDelegate {
func hotlineStatusChanged(status: HotlineClientStatus) {}
func hotlineReceivedAgreement(text: String) {}
+ func hotlineReceivedErrorMessage(code: UInt32, message: String?) {}
func hotlineReceivedChatMessage(message: String) {}
func hotlineReceivedUserList(users: [HotlineUser]) {}
func hotlineReceivedServerMessage(message: String) {}
@@ -376,8 +378,9 @@ class HotlineClient: NetSocketDelegate {
if packet.errorCode != 0 {
let errorField: HotlineTransactionField? = packet.getField(type: .errorText)
print("HotlineClient 😵 \(packet.errorCode): \(errorField?.getString() ?? "")")
+ self.delegate?.hotlineReceivedErrorMessage(code: packet.errorCode, message: errorField?.getString())
}
-
+
guard let replyCallbackInfo = self.transactionLog[packet.id] else {
print("Hmm, no reply waiting though")
return
@@ -391,7 +394,6 @@ class HotlineClient: NetSocketDelegate {
guard packet.errorCode == 0 else {
let errorField: HotlineTransactionField? = packet.getField(type: .errorText)
- print("HotlineClient 😵 \(packet.errorCode): \(errorField?.getString() ?? "")")
replyCallback?(packet, .error(packet.errorCode, errorField?.getString()))
return
}
diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift
index e69116e..11781c7 100644
--- a/Hotline/Models/Hotline.swift
+++ b/Hotline/Models/Hotline.swift
@@ -140,6 +140,8 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileDownloadClientDelega
var downloads: [HotlineTransferClient] = []
var unreadInstantMessages: [UInt16:UInt16] = [:]
var unreadPublicChat: Bool = false
+ var errorDisplayed: Bool = false
+ var errorMessage: String? = nil
@ObservationIgnored var bannerClient: HotlineFilePreviewClient?
#if os(macOS)
@@ -902,8 +904,11 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileDownloadClientDelega
self.access = options
}
- func hotlineReceivedError(message: String) {
+ func hotlineReceivedErrorMessage(code: UInt32, message: String?) {
+ print("Hotline: received error message \(code)", message.debugDescription)
+ self.errorDisplayed = (message != nil) // Show error if there is a message to display.
+ self.errorMessage = message
}
// MARK: - Hotline Transfer Delegate
diff --git a/Hotline/macOS/ServerView.swift b/Hotline/macOS/ServerView.swift
index 8813db8..55ac127 100644
--- a/Hotline/macOS/ServerView.swift
+++ b/Hotline/macOS/ServerView.swift
@@ -227,6 +227,9 @@ struct ServerView: View {
.onDisappear {
model.disconnect()
}
+ .alert(model.errorMessage ?? "Server Message", isPresented: $model.errorDisplayed) {
+ Button("OK") {}
+ }
.task {
var address = server.address
if server.port != HotlinePorts.DefaultServerPort {