I using Angular's $http to get questions, which expects a promise in retu, either success or error:
Question.getQuestions().success(function (res) {
...
}).error(function (err) {});
In my method, I need to check if token is expired, if so, refresh, then make the request to /questions and retu the promise. Otherwise, just make the request to /questions as usual:
getQuestions: function() {
var get = function() {
retu $http({
method: 'GET',
url: url + ver + '/questions',
...
});
};
if (Auth.tokenIsExpired()) {
retu Auth.refreshToken(get);
} else {
retu get();
}
},
The refresh is another $http which relies on a promise, then calls the get() callback.
Auth {...
refreshToken: function(callback) {
...
_this.getAuth(OAuth).success(function (access_obj) {
//set token
callback();
})...
All of these methods are called as expected, but am getting error:
Caot read property 'success' of undefined
This is because Auth.refreshToken(get) is not retuing the /questions $http call as it should. How can I retu the promise from that back to the original Question.getQuestions()?
