multiplatform: check temporary proxy error (#4442)

* android: check temporary proxy error

* version error

* errors
This commit is contained in:
spaced4ndy
2024-07-11 21:44:31 +04:00
committed by GitHub
parent 2dff94cbb4
commit 71ad8f2fd1
2 changed files with 114 additions and 0 deletions

View File

@@ -1809,6 +1809,80 @@ object ChatController {
)
true
}
r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorAgent
&& r.chatError.agentError is AgentErrorType.BROKER
&& r.chatError.agentError.brokerErr is BrokerErrorType.HOST -> {
AlertManager.shared.showAlertMsg(
generalGetString(MR.strings.connection_error),
String.format(generalGetString(MR.strings.network_error_broker_host_desc), serverHostname(r.chatError.agentError.brokerAddress))
)
true
}
r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorAgent
&& r.chatError.agentError is AgentErrorType.BROKER
&& r.chatError.agentError.brokerErr is BrokerErrorType.TRANSPORT
&& r.chatError.agentError.brokerErr.transportErr is SMPTransportError.Version -> {
AlertManager.shared.showAlertMsg(
generalGetString(MR.strings.connection_error),
String.format(generalGetString(MR.strings.network_error_broker_version_desc), serverHostname(r.chatError.agentError.brokerAddress))
)
true
}
r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorAgent
&& r.chatError.agentError is AgentErrorType.SMP
&& r.chatError.agentError.smpErr is SMPErrorType.PROXY ->
proxyErrorAlert(r.chatError.agentError.smpErr.proxyErr)
r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorAgent
&& r.chatError.agentError is AgentErrorType.PROXY
&& r.chatError.agentError.proxyErr is ProxyClientError.ProxyProtocolError
&& r.chatError.agentError.proxyErr.protocolErr is SMPErrorType.PROXY ->
proxyErrorAlert(r.chatError.agentError.proxyErr.protocolErr.proxyErr)
else -> false
}
}
private fun proxyErrorAlert(pe: ProxyError): Boolean {
return when {
pe is ProxyError.BROKER
&& pe.brokerErr is BrokerErrorType.TIMEOUT -> {
AlertManager.shared.showAlertMsg(
generalGetString(MR.strings.private_routing_error),
generalGetString(MR.strings.please_try_later)
)
true
}
pe is ProxyError.BROKER
&& pe.brokerErr is BrokerErrorType.NETWORK -> {
AlertManager.shared.showAlertMsg(
generalGetString(MR.strings.private_routing_error),
generalGetString(MR.strings.please_try_later)
)
true
}
pe is ProxyError.NO_SESSION -> {
AlertManager.shared.showAlertMsg(
generalGetString(MR.strings.private_routing_error),
generalGetString(MR.strings.please_try_later)
)
true
}
pe is ProxyError.BROKER
&& pe.brokerErr is BrokerErrorType.HOST -> {
AlertManager.shared.showAlertMsg(
generalGetString(MR.strings.private_routing_error),
generalGetString(MR.strings.srv_error_host)
)
true
}
pe is ProxyError.BROKER
&& pe.brokerErr is BrokerErrorType.TRANSPORT
&& pe.brokerErr.transportErr is SMPTransportError.Version -> {
AlertManager.shared.showAlertMsg(
generalGetString(MR.strings.private_routing_error),
generalGetString(MR.strings.srv_error_version)
)
true
}
else -> false
}
}
@@ -5500,6 +5574,7 @@ sealed class AgentErrorType {
is SMP -> "SMP ${smpErr.string}"
// is NTF -> "NTF ${ntfErr.string}"
is XFTP -> "XFTP ${xftpErr.string}"
is PROXY -> "PROXY $proxyServer $relayServer ${proxyErr.string}"
is RCP -> "RCP ${rcpErr.string}"
is BROKER -> "BROKER ${brokerErr.string}"
is AGENT -> "AGENT ${agentErr.string}"
@@ -5512,6 +5587,7 @@ sealed class AgentErrorType {
@Serializable @SerialName("SMP") class SMP(val smpErr: SMPErrorType): AgentErrorType()
// @Serializable @SerialName("NTF") class NTF(val ntfErr: SMPErrorType): AgentErrorType()
@Serializable @SerialName("XFTP") class XFTP(val xftpErr: XFTPErrorType): AgentErrorType()
@Serializable @SerialName("PROXY") class PROXY(val proxyServer: String, val relayServer: String, val proxyErr: ProxyClientError): AgentErrorType()
@Serializable @SerialName("RCP") class RCP(val rcpErr: RCErrorType): AgentErrorType()
@Serializable @SerialName("BROKER") class BROKER(val brokerAddress: String, val brokerErr: BrokerErrorType): AgentErrorType()
@Serializable @SerialName("AGENT") class AGENT(val agentErr: SMPAgentError): AgentErrorType()
@@ -5576,22 +5652,42 @@ sealed class SMPErrorType {
is BLOCK -> "BLOCK"
is SESSION -> "SESSION"
is CMD -> "CMD ${cmdErr.string}"
is PROXY -> "PROXY ${proxyErr.string}"
is AUTH -> "AUTH"
is CRYPTO -> "CRYPTO"
is QUOTA -> "QUOTA"
is NO_MSG -> "NO_MSG"
is LARGE_MSG -> "LARGE_MSG"
is EXPIRED -> "EXPIRED"
is INTERNAL -> "INTERNAL"
}
@Serializable @SerialName("BLOCK") class BLOCK: SMPErrorType()
@Serializable @SerialName("SESSION") class SESSION: SMPErrorType()
@Serializable @SerialName("CMD") class CMD(val cmdErr: ProtocolCommandError): SMPErrorType()
@Serializable @SerialName("PROXY") class PROXY(val proxyErr: ProxyError): SMPErrorType()
@Serializable @SerialName("AUTH") class AUTH: SMPErrorType()
@Serializable @SerialName("CRYPTO") class CRYPTO: SMPErrorType()
@Serializable @SerialName("QUOTA") class QUOTA: SMPErrorType()
@Serializable @SerialName("NO_MSG") class NO_MSG: SMPErrorType()
@Serializable @SerialName("LARGE_MSG") class LARGE_MSG: SMPErrorType()
@Serializable @SerialName("EXPIRED") class EXPIRED: SMPErrorType()
@Serializable @SerialName("INTERNAL") class INTERNAL: SMPErrorType()
}
@Serializable
sealed class ProxyError {
val string: String get() = when (this) {
is PROTOCOL -> "PROTOCOL ${protocolErr.string}"
is BROKER -> "BROKER ${brokerErr.string}"
is BASIC_AUTH -> "BASIC_AUTH"
is NO_SESSION -> "NO_SESSION"
}
@Serializable @SerialName("PROTOCOL") class PROTOCOL(val protocolErr: SMPErrorType): ProxyError()
@Serializable @SerialName("BROKER") class BROKER(val brokerErr: BrokerErrorType): ProxyError()
@Serializable @SerialName("BASIC_AUTH") class BASIC_AUTH: ProxyError()
@Serializable @SerialName("NO_SESSION") class NO_SESSION: ProxyError()
}
@Serializable
sealed class ProtocolCommandError {
val string: String get() = when (this) {
@@ -5614,12 +5710,14 @@ sealed class ProtocolCommandError {
sealed class SMPTransportError {
val string: String get() = when (this) {
is BadBlock -> "badBlock"
is Version -> "version"
is LargeMsg -> "largeMsg"
is BadSession -> "badSession"
is NoServerAuth -> "noServerAuth"
is Handshake -> "handshake ${handshakeErr.string}"
}
@Serializable @SerialName("badBlock") class BadBlock: SMPTransportError()
@Serializable @SerialName("version") class Version: SMPTransportError()
@Serializable @SerialName("largeMsg") class LargeMsg: SMPTransportError()
@Serializable @SerialName("badSession") class BadSession: SMPTransportError()
@Serializable @SerialName("noServerAuth") class NoServerAuth: SMPTransportError()
@@ -5692,6 +5790,18 @@ sealed class XFTPErrorType {
@Serializable @SerialName("INTERNAL") object INTERNAL: XFTPErrorType()
}
@Serializable
sealed class ProxyClientError {
val string: String get() = when (this) {
is ProxyProtocolError -> "ProxyProtocolError $protocolErr"
is ProxyUnexpectedResponse -> "ProxyUnexpectedResponse $responseStr"
is ProxyResponseError -> "ProxyResponseError $responseErr"
}
@Serializable @SerialName("protocolError") class ProxyProtocolError(val protocolErr: SMPErrorType): ProxyClientError()
@Serializable @SerialName("unexpectedResponse") class ProxyUnexpectedResponse(val responseStr: String): ProxyClientError()
@Serializable @SerialName("responseError") class ProxyResponseError(val responseErr: SMPErrorType): ProxyClientError()
}
@Serializable
sealed class RCErrorType {
val string: String get() = when (this) {

View File

@@ -112,6 +112,10 @@
<string name="connection_timeout">Connection timeout</string>
<string name="connection_error">Connection error</string>
<string name="network_error_desc">Please check your network connection with %1$s and try again.</string>
<string name="network_error_broker_host_desc">Server address is incompatible with network settings: %1$s.</string>
<string name="network_error_broker_version_desc">Server version is incompatible with your app: %1$s.</string>
<string name="private_routing_error">Private routing error</string>
<string name="please_try_later">Please try later.</string>
<string name="error_sending_message">Error sending message</string>
<string name="error_creating_message">Error creating message</string>
<string name="error_loading_details">Error loading details</string>