       return @sendError error.message, event.data if error?
 
       @rateLimit @socket.id, type, (error) =>
-        return @sendError error.message, event.data, 429 if error?
+        return @closeWithError error, [type,data], 429 if error?
         return @emit type, data if type == 'identity'
 
         @authDevice @uuid, @token, (error, authedDevice)=>


  rateLimit: (id, type, callback=->) =>
    throttle = @throttles[type] ? @throttles.query
    callback() unless throttle?
    throttle.rateLimit id, (error, isLimited) =>
      debug 'rateLimit', id, type, isLimited
      return callback error if error?
      return callback new Error('request exceeds rate limit') if isLimited
      callback()

  onSocketData: (data) =>
    @sendFrame 'data', data



module.exports = MeshbluWebsocketHandler
