           @sock.on 'error', (error) =>
             setImmediate => @emit 'error', error
 
-            if not hasConnected
+            if not @hasConnected
               logger.error "WebSocket connect error:", error
               reject error
             else

        resolve()
      else
        data = auth.socketAuth @keys, @sessionUuid
        hasConnected = false

        if data?
          logger.info "Finished assembling auth data:\n

              
              logger.info "Connection closed. Reconnecting in 5 seconds."

              setTimeout reconnect, @autoReconnectDelay
              previousDelay = @autoReconnectDelay
              minimumDelay = Math.max(defaultReconnectDelay, previousDelay)
              nextDelay = Math.min(minimumDelay, maxReconnectDelay) * 2
              @autoReconnectDelay = nextDelay

            else
              setImmediate => @emit 'close'

              if @hasConnected
                logger.info "Pub/Sub WebSocket closed."
              else
                message = "Websocket closed before the connection was established"
