mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 09:06:06 -04:00
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:
parent
76005c44f7
commit
db3e1d73c6
4 changed files with 16 additions and 30 deletions
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue