       options.stub = null
       $.ajax(options)
         .done (data)->
-          unless data.result is "error"
+          if not data or data.result is "error"
+            async.reject data
+          else
             async.resolve data
-          else
-            async.reject data
+
         .fail (err)->
           async.reject err
         .always =>

      "#{name}#{url}"

  class ServerClient
    constructor:->
      @lock = new Lock

    _isServer:-> true


define ["jquery"],($)->

  class Lock
    constructor:(@accept_logs=false)->
      @_locks = {}

    trylock:(url, name)->
      key = @hash url, name
      if !!@_locks[key]
        console.warn "tryLock #{url} #{name}" if @accept_logs
        false
      else
        @_locks[key] = true
