mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-29 04:39:53 +00:00
mobile: broker error type (#1475)
* mobile: broker error type * fix * ios: update libraries * change AgentErrorType to String
This commit is contained in:
parent
c43ba7bf23
commit
e44e9a0940
17 changed files with 39 additions and 30 deletions
|
@ -1266,7 +1266,7 @@ sealed class CIStatus {
|
|||
@Serializable @SerialName("sndNew") class SndNew: CIStatus()
|
||||
@Serializable @SerialName("sndSent") class SndSent: CIStatus()
|
||||
@Serializable @SerialName("sndErrorAuth") class SndErrorAuth: CIStatus()
|
||||
@Serializable @SerialName("sndError") class SndError(val agentError: AgentErrorType): CIStatus()
|
||||
@Serializable @SerialName("sndError") class SndError(val agentError: String): CIStatus()
|
||||
@Serializable @SerialName("rcvNew") class RcvNew: CIStatus()
|
||||
@Serializable @SerialName("rcvRead") class RcvRead: CIStatus()
|
||||
}
|
||||
|
|
|
@ -28,8 +28,7 @@ import chat.simplex.app.views.call.*
|
|||
import chat.simplex.app.views.helpers.*
|
||||
import chat.simplex.app.views.newchat.ConnectViaLinkTab
|
||||
import chat.simplex.app.views.onboarding.OnboardingStage
|
||||
import chat.simplex.app.views.usersettings.NotificationPreviewMode
|
||||
import chat.simplex.app.views.usersettings.NotificationsMode
|
||||
import chat.simplex.app.views.usersettings.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.datetime.Clock
|
||||
import kotlinx.datetime.Instant
|
||||
|
@ -958,7 +957,7 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
|
|||
&& r.chatError.agentError.brokerErr is BrokerErrorType.TIMEOUT -> {
|
||||
AlertManager.shared.showAlertMsg(
|
||||
generalGetString(R.string.connection_timeout),
|
||||
generalGetString(R.string.network_error_desc)
|
||||
String.format(generalGetString(R.string.network_error_desc), serverHostname(r.chatError.agentError.brokerAddress))
|
||||
)
|
||||
true
|
||||
}
|
||||
|
@ -967,7 +966,7 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
|
|||
&& r.chatError.agentError.brokerErr is BrokerErrorType.NETWORK -> {
|
||||
AlertManager.shared.showAlertMsg(
|
||||
generalGetString(R.string.connection_error),
|
||||
generalGetString(R.string.network_error_desc)
|
||||
String.format(generalGetString(R.string.network_error_desc), serverHostname(r.chatError.agentError.brokerAddress))
|
||||
)
|
||||
true
|
||||
}
|
||||
|
@ -2750,7 +2749,7 @@ sealed class AgentErrorType {
|
|||
@Serializable @SerialName("CMD") class CMD(val cmdErr: CommandErrorType): AgentErrorType()
|
||||
@Serializable @SerialName("CONN") class CONN(val connErr: ConnectionErrorType): AgentErrorType()
|
||||
@Serializable @SerialName("SMP") class SMP(val smpErr: SMPErrorType): AgentErrorType()
|
||||
@Serializable @SerialName("BROKER") class BROKER(val brokerErr: BrokerErrorType): AgentErrorType()
|
||||
@Serializable @SerialName("BROKER") class BROKER(val brokerAddress: String, val brokerErr: BrokerErrorType): AgentErrorType()
|
||||
@Serializable @SerialName("AGENT") class AGENT(val agentErr: SMPAgentError): AgentErrorType()
|
||||
@Serializable @SerialName("INTERNAL") class INTERNAL(val internalErr: String): AgentErrorType()
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ fun PreviewCIMetaViewSendFailed() {
|
|||
CIMetaView(
|
||||
chatItem = ChatItem.getSampleData(
|
||||
1, CIDirection.DirectSnd(), Clock.System.now(), "hello",
|
||||
status = CIStatus.SndError(AgentErrorType.CMD(CommandErrorType.SYNTAX()))
|
||||
status = CIStatus.SndError("CMD SYNTAX")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ fun ChatItemView(
|
|||
showMsgDeliveryErrorAlert(generalGetString(R.string.message_delivery_error_desc))
|
||||
}
|
||||
is CIStatus.SndError -> {
|
||||
showMsgDeliveryErrorAlert(generalGetString(R.string.unknown_error) + ": ${cItem.meta.itemStatus.agentError.string}")
|
||||
showMsgDeliveryErrorAlert(generalGetString(R.string.unknown_error) + ": ${cItem.meta.itemStatus.agentError}")
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
|
|
|
@ -196,5 +196,5 @@ suspend fun testServerConnection(server: ServerCfg, m: ChatModel): Pair<ServerCf
|
|||
server.copy(tested = false) to null
|
||||
}
|
||||
|
||||
fun serverHostname(srv: ServerCfg): String =
|
||||
parseServerAddress(srv.server)?.hostnames?.firstOrNull() ?: srv.server
|
||||
fun serverHostname(srv: String): String =
|
||||
parseServerAddress(srv)?.hostnames?.firstOrNull() ?: srv
|
||||
|
|
|
@ -301,7 +301,7 @@ private suspend fun runServersTest(servers: List<ServerCfg>, m: ChatModel, onUpd
|
|||
// toList() is important. Otherwise, Compose will not redraw the screen after first update
|
||||
onUpdated(updatedServers.toList())
|
||||
if (f != null) {
|
||||
fs[serverHostname(updatedServer)] = f
|
||||
fs[serverHostname(updatedServer.server)] = f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<!-- API Error Responses - SimpleXAPI.kt -->
|
||||
<string name="connection_timeout">Verbindungszeitüberschreitung</string>
|
||||
<string name="connection_error">Verbindungsfehler</string>
|
||||
<string name="network_error_desc">Bitte überprüfen Sie Ihre Netzwerkverbindung und versuchen Sie es erneut.</string>
|
||||
<string name="network_error_desc">*** Bitte überprüfen Sie Ihre Netzwerkverbindung mit <xliff:g id="serverHost" example="smp.simplex.im">%1$s</xliff:g> und versuchen Sie es erneut.</string>
|
||||
<string name="error_sending_message">Fehler beim Senden der Nachricht</string>
|
||||
<string name="error_adding_members">Fehler beim Hinzufügen von Mitgliedern</string>
|
||||
<string name="error_joining_group">Fehler beim Beitritt zur Gruppe</string>
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<!-- API Error Responses - SimpleXAPI.kt -->
|
||||
<string name="connection_timeout">Превышено время соединения</string>
|
||||
<string name="connection_error">Ошибка соединения</string>
|
||||
<string name="network_error_desc">Пожалуйста, проверьте ваше соединение с сетью и попробуйте еще раз.</string>
|
||||
<string name="network_error_desc">Пожалуйста, проверьте ваше соединение с сервером <xliff:g id="serverHost" example="smp.simplex.im">%1$s</xliff:g> и попробуйте еще раз.</string>
|
||||
<string name="error_sending_message">Ошибка при отправке сообщения</string>
|
||||
<string name="error_adding_members">Ошибка при добавлении членов группы</string>
|
||||
<string name="error_joining_group">Ошибка при вступлении в группу</string>
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<!-- API Error Responses - SimpleXAPI.kt -->
|
||||
<string name="connection_timeout">Connection timeout</string>
|
||||
<string name="connection_error">Connection error</string>
|
||||
<string name="network_error_desc">Please check your network connection and try again.</string>
|
||||
<string name="network_error_desc">Please check your network connection with <xliff:g id="serverHost" example="smp.simplex.im">%1$s</xliff:g> and try again.</string>
|
||||
<string name="error_sending_message">Error sending message</string>
|
||||
<string name="error_adding_members">Error adding member(s)</string>
|
||||
<string name="error_joining_group">Error joining group</string>
|
||||
|
|
|
@ -603,16 +603,16 @@ func apiReceiveFile(fileId: Int64, inline: Bool) async -> AChatItem? {
|
|||
func networkErrorAlert(_ r: ChatResponse) -> Bool {
|
||||
let am = AlertManager.shared
|
||||
switch r {
|
||||
case .chatCmdError(.errorAgent(.BROKER(.TIMEOUT))):
|
||||
case let .chatCmdError(.errorAgent(.BROKER(addr, .TIMEOUT))):
|
||||
am.showAlertMsg(
|
||||
title: "Connection timeout",
|
||||
message: "Please check your network connection and try again."
|
||||
message: "Please check your network connection with \(serverHostname(addr)) and try again."
|
||||
)
|
||||
return true
|
||||
case .chatCmdError(.errorAgent(.BROKER(.NETWORK))):
|
||||
case let .chatCmdError(.errorAgent(.BROKER(addr, .NETWORK))):
|
||||
am.showAlertMsg(
|
||||
title: "Connection error",
|
||||
message: "Please check your network connection and try again."
|
||||
message: "Please check your network connection with \(serverHostname(addr)) and try again."
|
||||
)
|
||||
return true
|
||||
default:
|
||||
|
@ -1146,7 +1146,7 @@ func processContactSubError(_ contact: Contact, _ chatError: ChatError) {
|
|||
m.updateContact(contact)
|
||||
var err: String
|
||||
switch chatError {
|
||||
case .errorAgent(agentError: .BROKER(brokerErr: .NETWORK)): err = "network"
|
||||
case .errorAgent(agentError: .BROKER(_, .NETWORK)): err = "network"
|
||||
case .errorAgent(agentError: .SMP(smpErr: .AUTH)): err = "contact deleted"
|
||||
default: err = String(describing: chatError)
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ struct FramedItemView: View {
|
|||
case .sndErrorAuth:
|
||||
v.onTapGesture { msgDeliveryError("Most likely this contact has deleted the connection with you.") }
|
||||
case let .sndError(agentError):
|
||||
v.onTapGesture { msgDeliveryError("Unexpected error: \(String(describing: agentError))") }
|
||||
v.onTapGesture { msgDeliveryError("Unexpected error: \(agentError)") }
|
||||
default: v
|
||||
}
|
||||
}
|
||||
|
|
|
@ -402,10 +402,10 @@ struct ErrorAlert {
|
|||
|
||||
func getErrorAlert(_ error: Error, _ title: LocalizedStringKey) -> ErrorAlert {
|
||||
switch error as? ChatResponse {
|
||||
case .chatCmdError(.errorAgent(.BROKER(.TIMEOUT))):
|
||||
return ErrorAlert(title: "Connection timeout", message: "Please check your network connection and try again.")
|
||||
case .chatCmdError(.errorAgent(.BROKER(.NETWORK))):
|
||||
return ErrorAlert(title: "Connection error", message: "Please check your network connection and try again.")
|
||||
case let .chatCmdError(.errorAgent(.BROKER(addr, .TIMEOUT))):
|
||||
return ErrorAlert(title: "Connection timeout", message: "Please check your network connection with \(serverHostname(addr)) and try again.")
|
||||
case let .chatCmdError(.errorAgent(.BROKER(addr, .NETWORK))):
|
||||
return ErrorAlert(title: "Connection error", message: "Please check your network connection with \(serverHostname(addr)) and try again.")
|
||||
default:
|
||||
return ErrorAlert(title: title, message: "Error: \(responseError(error))")
|
||||
}
|
||||
|
|
|
@ -155,8 +155,8 @@ func testServerConnection(server: Binding<ServerCfg>) async -> SMPTestFailure? {
|
|||
}
|
||||
}
|
||||
|
||||
func serverHostname(_ srv: ServerCfg) -> String {
|
||||
parseServerAddress(srv.server)?.hostnames.first ?? srv.server
|
||||
func serverHostname(_ srv: String) -> String {
|
||||
parseServerAddress(srv)?.hostnames.first ?? srv
|
||||
}
|
||||
|
||||
struct SMPServerView_Previews: PreviewProvider {
|
||||
|
|
|
@ -222,7 +222,7 @@ struct SMPServersView: View {
|
|||
for i in 0..<servers.count {
|
||||
if servers[i].enabled {
|
||||
if let f = await testServerConnection(server: $servers[i]) {
|
||||
fs[serverHostname(servers[i])] = f
|
||||
fs[serverHostname(servers[i].server)] = f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,11 @@
|
|||
5CE4407927ADB701007B033A /* EmojiItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CE4407827ADB701007B033A /* EmojiItemView.swift */; };
|
||||
5CEACCE327DE9246000BD591 /* ComposeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CEACCE227DE9246000BD591 /* ComposeView.swift */; };
|
||||
5CEACCED27DEA495000BD591 /* MsgContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CEACCEC27DEA495000BD591 /* MsgContentView.swift */; };
|
||||
5CEE87AA293B3EF100D42FE2 /* libffi.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CEE87A5293B3EF100D42FE2 /* libffi.a */; };
|
||||
5CEE87AB293B3EF100D42FE2 /* libgmp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CEE87A6293B3EF100D42FE2 /* libgmp.a */; };
|
||||
5CEE87AC293B3EF100D42FE2 /* libHSsimplex-chat-4.3.0-GPZqasc9wbbBzOZyUtfq0X-ghc8.10.7.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CEE87A7293B3EF100D42FE2 /* libHSsimplex-chat-4.3.0-GPZqasc9wbbBzOZyUtfq0X-ghc8.10.7.a */; };
|
||||
5CEE87AD293B3EF100D42FE2 /* libgmpxx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CEE87A8293B3EF100D42FE2 /* libgmpxx.a */; };
|
||||
5CEE87AE293B3EF200D42FE2 /* libHSsimplex-chat-4.3.0-GPZqasc9wbbBzOZyUtfq0X.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CEE87A9293B3EF100D42FE2 /* libHSsimplex-chat-4.3.0-GPZqasc9wbbBzOZyUtfq0X.a */; };
|
||||
5CFA59C42860BC6200863A68 /* MigrateToAppGroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CFA59C32860BC6200863A68 /* MigrateToAppGroupView.swift */; };
|
||||
5CFA59D12864782E00863A68 /* ChatArchiveView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CFA59CF286477B400863A68 /* ChatArchiveView.swift */; };
|
||||
5CFE0921282EEAF60002594B /* ZoomableScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CFE0920282EEAF60002594B /* ZoomableScrollView.swift */; };
|
||||
|
@ -335,6 +340,11 @@
|
|||
5CE4407827ADB701007B033A /* EmojiItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiItemView.swift; sourceTree = "<group>"; };
|
||||
5CEACCE227DE9246000BD591 /* ComposeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeView.swift; sourceTree = "<group>"; };
|
||||
5CEACCEC27DEA495000BD591 /* MsgContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MsgContentView.swift; sourceTree = "<group>"; };
|
||||
5CEE87A5293B3EF100D42FE2 /* libffi.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libffi.a; sourceTree = "<group>"; };
|
||||
5CEE87A6293B3EF100D42FE2 /* libgmp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgmp.a; sourceTree = "<group>"; };
|
||||
5CEE87A7293B3EF100D42FE2 /* libHSsimplex-chat-4.3.0-GPZqasc9wbbBzOZyUtfq0X-ghc8.10.7.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "libHSsimplex-chat-4.3.0-GPZqasc9wbbBzOZyUtfq0X-ghc8.10.7.a"; sourceTree = "<group>"; };
|
||||
5CEE87A8293B3EF100D42FE2 /* libgmpxx.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgmpxx.a; sourceTree = "<group>"; };
|
||||
5CEE87A9293B3EF100D42FE2 /* libHSsimplex-chat-4.3.0-GPZqasc9wbbBzOZyUtfq0X.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "libHSsimplex-chat-4.3.0-GPZqasc9wbbBzOZyUtfq0X.a"; sourceTree = "<group>"; };
|
||||
5CFA59C32860BC6200863A68 /* MigrateToAppGroupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MigrateToAppGroupView.swift; sourceTree = "<group>"; };
|
||||
5CFA59CF286477B400863A68 /* ChatArchiveView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatArchiveView.swift; sourceTree = "<group>"; };
|
||||
5CFE0920282EEAF60002594B /* ZoomableScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ZoomableScrollView.swift; path = Shared/Views/ZoomableScrollView.swift; sourceTree = SOURCE_ROOT; };
|
||||
|
|
|
@ -734,7 +734,7 @@ public struct SMPTestFailure: Decodable, Error, Equatable {
|
|||
switch testError {
|
||||
case .SMP(.AUTH):
|
||||
return err + " " + NSLocalizedString("Server requires authorization to create queues, check password", comment: "server test error")
|
||||
case .BROKER(.NETWORK):
|
||||
case .BROKER(_, .NETWORK):
|
||||
return err + " " + NSLocalizedString("Possibly, certificate fingerprint in server address is incorrect", comment: "server test error")
|
||||
default:
|
||||
return err
|
||||
|
@ -1081,7 +1081,7 @@ public enum AgentErrorType: Decodable {
|
|||
case CONN(connErr: ConnectionErrorType)
|
||||
case SMP(smpErr: ProtocolErrorType)
|
||||
case NTF(ntfErr: ProtocolErrorType)
|
||||
case BROKER(brokerErr: BrokerErrorType)
|
||||
case BROKER(brokerAddress: String, brokerErr: BrokerErrorType)
|
||||
case AGENT(agentErr: SMPAgentError)
|
||||
case INTERNAL(internalErr: String)
|
||||
}
|
||||
|
|
|
@ -1595,7 +1595,7 @@ public enum CIStatus: Decodable {
|
|||
case sndNew
|
||||
case sndSent
|
||||
case sndErrorAuth
|
||||
case sndError(agentError: AgentErrorType)
|
||||
case sndError(agentError: String)
|
||||
case rcvNew
|
||||
case rcvRead
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue