From cc27f99e473fd009f0078cd4c6895f7e8ffb70b1 Mon Sep 17 00:00:00 2001 From: Viktoriia Kostyleva Date: Fri, 14 Oct 2022 12:11:35 +0300 Subject: [PATCH] Change error model sending to socket --- .../Tunnel/TunnelRouteCollection.swift | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Root/RouteCollections/Tunnel/TunnelRouteCollection.swift b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Root/RouteCollections/Tunnel/TunnelRouteCollection.swift index 10e4474..477cb50 100644 --- a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Root/RouteCollections/Tunnel/TunnelRouteCollection.swift +++ b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Root/RouteCollections/Tunnel/TunnelRouteCollection.swift @@ -29,6 +29,7 @@ enum TunnelRouteEvent: String { private struct Constants { let path: PathComponent = "connection" let connectionType = "tunnelStatus" + let error = "error" } private let constants = Constants() @@ -127,19 +128,23 @@ extension TunnelRouteCollection { extension TunnelRouteCollection { private func send(error: SingleInnerError) { - let data = error.toData()?.string ?? error.error.message - delegate?.send(event: data) + let message = error.error.toData()?.string ?? error.error.message + send(key: constants.error, value: message) } private func send(warning: SingleInnerError) { - let data = warning.toData()?.string ?? warning.error.message - delegate?.send(event: data) + let message = warning.error.toData()?.string ?? warning.error.message + send(key: constants.error, value: message) } private func updateConnection(isConnected: Bool) { + send(key: constants.connectionType, value: isConnected ? "connected" : "disconnected") + } + + private func send(key: String, value: String) { let event = InfoEvent( - type: constants.connectionType, - value: isConnected ? "connected" : "disconnected" + type: key, + value: value ) if let dataString = event.toData()?.string { delegate?.send(event: dataString)