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

@ -42,20 +42,20 @@ matrixWebClient.config(['$routeProvider', '$provide', '$httpProvider',
redirectTo: '/rooms'
});
$provide.factory('AccessTokenInterceptor', function ($q) {
$provide.factory('AccessTokenInterceptor', ['$q', '$rootScope',
function ($q, $rootScope) {
return {
responseError: function(rejection) {
console.log("Rejection: " + JSON.stringify(rejection));
if (rejection.status === 403 && "data" in rejection &&
"errcode" in rejection.data &&
rejection.data.errcode === "M_UNKNOWN_TOKEN") {
console.log("TODO: Got a 403 with an unknown token. Logging out.")
// TODO logout
console.log("Got a 403 with an unknown token. Logging out.")
$rootScope.$broadcast("M_UNKNOWN_TOKEN");
}
return $q.reject(rejection);
}
};
});
}]);
$httpProvider.interceptors.push('AccessTokenInterceptor');
}]);