Move the unknown token broadcast to the interceptor. Return the $http promise and not a wrapped one via $q. Everything now needs a level deeper nesting. Fixed registration and login.

This commit is contained in:
Kegan Dougal 2014-08-14 15:36:40 +01:00
parent 76005c44f7
commit db3e1d73c6
4 changed files with 16 additions and 30 deletions

View file

@ -49,32 +49,13 @@ angular.module('matrixService', [])
if (path.indexOf(prefixPath) !== 0) {
path = prefixPath + path;
}
// Do not directly return the $http instance but return a promise
// with enriched or cleaned information
var deferred = $q.defer();
$http({
return $http({
method: method,
url: baseUrl + path,
params: params,
data: data,
headers: headers
})
.success(function(data, status, headers, config) {
deferred.resolve(data, status, headers, config);
})
.error(function(data, status, headers, config) {
// Enrich the error callback with an human readable error reason
var reason = data.error;
if (!data.error) {
reason = JSON.stringify(data);
}
deferred.reject(reason, data, status, headers, config);
if (403 === status && "M_UNKNOWN_TOKEN" === data.errcode) {
// The access token is no more valid, broadcast the issue
$rootScope.$broadcast("M_UNKNOWN_TOKEN");
}
});
return deferred.promise;
};