Skip to content

Commit

Permalink
Change error model sending to socket
Browse files Browse the repository at this point in the history
  • Loading branch information
VictoriaKostyleva committed Oct 14, 2022
1 parent f46bf4c commit cc27f99
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum TunnelRouteEvent: String {
private struct Constants {
let path: PathComponent = "connection"
let connectionType = "tunnelStatus"
let error = "error"
}
private let constants = Constants()

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cc27f99

Please sign in to comment.