               humanReadable = JSON.stringify body, null, 2
               deferred.reject humanReadable
     _page()
-    deferred.promise+    deferred.promise

# TODO: move it to `sphere-node-client` or `sphere-node-utils`
module.exports =

  pagedFetch: (rest, endpoint)->
    deferred = Q.defer()
    _page = (offset = 0, limit = 100, total, acc = []) ->
      if total? and (offset + limit) >= total + limit

          message: ' done'
        deferred.resolve acc
      else
        rest.GET "#{endpoint}?offset=#{offset}&limit=#{limit}", (error, response, body) ->
          unless total
            deferred.notify
              inProgress: true
