The interpectors for the angular http requests are kept in app/blocks/interceptor. There, there's a file called notification.interceptor.js
and there's no filter for the entities being displayed, so we need to configure it in some way:
(function() {
'use strict';
angular
.module('myApp')
.factory('notificationInterceptor', notificationInterceptor);
notificationInterceptor.$inject = ['$q', 'AlertService'];
function notificationInterceptor ($q, AlertService) {
var service = {
response: response
};
return service;
function response (response) {
var headers = Object.keys(response.headers()).filter(function (header) {
return header.indexOf('app-alert', header.length - 'app-alert'.length) !== -1 || header.indexOf('app-params', header.length - 'app-params'.length) !== -1;
}).sort();
var alertKey = response.headers(headers[0]);
if (angular.isString(alertKey) && alertKey.indexOf('myEntityToBeDisplayed') !== -1) {
AlertService.success(alertKey, { param : response.headers(headers[1])});
}
return response;
}
}
})();
Then, if we also want to show alerts or log the error responses from the server, the errorhandler.interceptor.js
intercepts each of the error responses happening. Tuning it a bit, there's the chance to show alerts for all of them:
(function() {
'use strict';
angular
.module('myApp')
.factory('errorHandlerInterceptor', errorHandlerInterceptor);
errorHandlerInterceptor.$inject = ['$q', '$rootScope'];
function errorHandlerInterceptor ($q, $rootScope) {
var service = {
responseError: responseError
};
return service;
function responseError (response) {
if (!(response.status === 401)) {
$rootScope.$emit('myApp.httpError', response);
}
return $q.reject(response);
}
}
})();
See also: