                 self.retries += 1
                 self.connectWithToken()
             } else if let error = error {
+                self.isClosedByError = true
                 self.onError?(error)
             }
         }

    private let operations = NSOperationQueue()
    private let socket: WebSocket
    private var isConnecting = false
    private var retries = 0
    private var maxRetries = 2


    }

    private func isAuthenticationFailure(error: NSError?) -> Bool {
        guard let error = error,
              let description = error.userInfo[NSLocalizedDescriptionKey] as? String else
        {
