Skip to content

Asynchronous task in response interceptor? #1153

@jpetitcolas

Description

@jpetitcolas

I am currently trying to implement ng-admin with a Loopback API. As Loopback provides collection length in a separate route (/api/cars/count), I would like to decorate the response with a totalCount property retrieved from this URL.

Here is what I've done so far:

app.run(['Restangular', '$http', function(RestangularProvider, $http) {
    RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
        if (operation !== 'getList') {
            deferred.resolve(data);
        }

        $http.get(url + '/count')
            .success(function(countData) {
                response.totalCount = countData.count;
                deferred.resolve(data);
            })
            .error(function(error) {
                deferred.reject(error);
            });
    });
}]);

Does Restangular interceptor deals correctly with asynchronous tasks?

Probably related to #893.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions