I want to write an error handling part in my application I use this code below but when error 500 occur its work right but there is a small or maybe big problem and thats the page load at first and after few second error page load , How can i remove this few second and go to error page directly without loading mainpage that release error? is there any way to load html template after execution of its controller?
var interceptor = ['$rootScope', '$q', function (scope, $q) {
function success(response) {
return response;
}
function error(response) {
var status = response.status;
if (status == 500) {
window.location= "http://www.domain.lan/#!/error";
return;
}
if (status == 403) {
// window.location = "dashboard";
return;
}
// otherwise
return $q.reject(responseInterceptors);
}
return function (promise) {
return promise.then(success, error);
}
}];
$httpProvider.responseInterceptors.push(interceptor);
I'm assuming that you are using angular ui-router.
1st thing you need to add one state in your $stateProvider config to understand 'error' state by ui-router.
Route config Code
And You did window.location and set the url, window.location causing page to refresh. Instead of using window.location use window.location.hash
Interception function change
Other way you can try the same $state.go('error'); don't forget to add $state dependancy.
Hope this will be helpful to you. Let me know if there is still any confusion.