Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notification can not be injected to httpInterceptor #138

Open
quchwe opened this issue Nov 6, 2017 · 1 comment
Open

notification can not be injected to httpInterceptor #138

quchwe opened this issue Nov 6, 2017 · 1 comment

Comments

@quchwe
Copy link

quchwe commented Nov 6, 2017

No description provided.

@cristian-milea
Copy link

cristian-milea commented Jan 27, 2018

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);
			}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants