You can create an interceptor to track all requests made by the $http service and catch any response errors. If you get 404 status for any request made, just redirect the user to the error page ( template/404.html in your case).
.factory('httpRequestInterceptor', function ($q) { return { 'responseError': function(rejection) { if(rejection.status === 404){
You will need to push the interceptor on $httpProvider in your configuration.
myApp.config( function ($httpProvider, $interpolateProvider, $routeProvider) { $httpProvider.interceptors.push('httpRequestInterceptor'); });
Here is a demo
Hooray!
source share