can we resolve any deferred with any response in angularjs

I cant understand, certain things in this code http://www.espeo.pl/2012/02/26/authentication-in-angularjs-application This code, this trying to resend same request(the one user requests before logging in) after the user logs in.

My question

  1. Inside the retry function, they are resloving a deffered with the response of a request that is sent after the user logs in. The response and the deffered are no way related to each other. Why they should do this?

-

function retry(req) {
    $http(req.config).then(function(response) {
        req.deferred.resolve(response);
    });
}

Please have a look at the code in the above url for understanding how the retry method works.

You can resolve a promise with whatever you want. In this case, a promise was returned to the application when the 401 status code/error was first encountered. Now, after the loginConfirmed event, the request is sent again and the response is used to resolve that promise.