angular-ui-notification icon indicating copy to clipboard operation
angular-ui-notification copied to clipboard

notification can not be injected to httpInterceptor

Open quchwe opened this issue 7 years ago • 1 comments

quchwe avatar Nov 06 '17 02:11 quchwe

hi. i used this approach, i don't know if it's the best

$httpProvider.interceptors.push(function ($q, $rootScope, $cookies, env, $injector) {
		let errorNotify = (err) => {
			var Notification = $injector.get('Notification');
			if(err.error && angular.isArray(err.error)){
				angular.forEach( err.error, (text) => {
					if(text.indexOf('_') !== -1) text = text.replace(/_/g, ' ');
					Notification.error(text);
				})	
			} else if(err.error){
				Notification.error(err.error);
			} else if(err) {
				Notification.error(err);
			}
		}
return {
.
.
.
'responseError': function (rejection) {
				if (parseInt(rejection.status) === 401) {
					$rootScope.$emit('unauthorized');
				}
				if (parseInt(rejection.status) === 500) {
				    errorNotify('Server Error. Please try again later.');
			    }
				return $q.reject(rejection);
			}
}

cristian-milea avatar Jan 27 '18 10:01 cristian-milea