               @emit 'messageSent', m
               delete @_pending[message.reply_to]
           else
-            @emit 'error', message.error
+            @emit 'error', if message.error? then message.error else message
             # TODO: resend?
         else
           if message.type not in ["file_created", "file_shared", "file_unshared", "file_comment", "file_public", "file_comment_edited", "file_comment_deleted", "file_change", "file_deleted", "star_added", "star_removed"]

    if not @connected
      return false
    else
      # We don't set any flags or anything here, since the event handling on the socket will do it
      @ws.close()
      return true


      else
        if message.reply_to
          if message.type == 'pong'
            @_lastPong = Date.now()
            delete @_pending[message.reply_to]
          else if message.ok
            console.log "Message "+message.reply_to+" was sent"
            if @_pending[message.reply_to]
              m = @_pending[message.reply_to]
