0

Here is the code:

var dbDelivery = Deliveries.get({deliveryId: delivery.id}, function() {
                if (!dbDelivery.id) {
                    toaster.pop('error', 'Error', 'That delivery does not exist. Somebody else may have deleted it.');
                    var deliveryIndex = $rootScope._.findIndex($scope.deliveries, 'id', delivery.id);
                    $scope.deliveries.splice(deliveryIndex, 1);
                    return;
                }
                dbDelivery.confirmed = true;
                dbDelivery.$update(function() { delivery.confirmed = true; }, ServerErrorAlert);
                return dbDelivery.$promise;
            })

Questions: 1) What happens if one calls multiple resource methods on a resource and returns the $promise? Does it just depend on the last method executed? 2) What is $resource looking for in order to reject the promise? I mean does it just depend on the response status code? If so which status codes result in a success and which result in error?

1 Answer 1

1

1) You can chain promises, but every $resource method call generate a new promise that represent the called method promise

2) It resolve the promise if the http response code is a success code 2xx (see)

Sign up to request clarification or add additional context in comments.

2 Comments

So in the code in the original post does the $promise get resolved after the $update method is successful? does the get method have any affect on the promise given the point at which it is called?
No, your code isn't a promise chain (see Chainig promise. The $update is in the success callback function and is called after the $resourse resolve the http get

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.