title: Alternative of $httpProvider.responseInterceptors
body: <p>What is alternative of  $httpProvider.responseInterceptors as it is discontinued in AngularJS V1.3?</p>
  
  <p>My interceptors which was working with Angular JS 1.2 is now not working with version 1.3</p>
  
  <pre><code>var angularErrorHandling = angular.module('xx-http-error-handling', []);
  angularErrorHandling.config(function ($provide, $httpProvider, $compileProvider) {
      var elementsList = $();
  
       push function to the responseInterceptors which will intercept 
       the http responses of the whole application
      $httpProvider.responseInterceptors.push(function ($timeout, $q) {
          return function (promise) {
              return promise.then(function (successResponse) {                
                  // if there is a successful response on POST, UPDATE or DELETE we display
                  // a success message with green background
                  if (successResponse.config.method.toUpperCase() == 'GET') {
                      var length = successResponse.data.length;                    
                      if (length == 0)
                      {
                          var countactivetoaster = $('#toast-container').find('.toast').length;
                          if (countactivetoaster == 0) {
                              toastr.warning('No Records Found!', '');
                          }
                      }                    
                      return successResponse;
                  }
                  else if (successResponse.config.method.toUpperCase() == 'PUT') {                   
                      toastr.success('Data Saved Sucessfully..', '');
                      return successResponse;
                  }
                  else if (successResponse.config.method.toUpperCase() == 'POST') {                   
                      toastr.success('Data Saved Sucessfully..', '');
                      return successResponse;
                  }
              },
              // if the message returns unsuccessful we display the error 
              function (errorResponse) {
                  switch (errorResponse.status) {
                      case 400: // if the status is 400 we return the error                           
                          toastr.error('400 error.', '');
                          // if we have found validation error messages we will loop through
                          // and display them
                          if (errorResponse.data.errors.length &gt; 0) {
                              for (var i = 0; i &lt; errorResponse.data.errors.length; i++) {
                                  toastr.error('xx-http-error-validation-message', '');
                              }
                          }
                          break;
                      case 401: // if the status is 401 we return access denied                            
                          toastr.error('Wrong email address or password!', '');
  
                          break;
                      case 403: // if the status is 403 we tell the user that authorization was denied                          
                          toastr.error('You have insufficient privileges to do what you want to do!', '');
                          break;
                      case 500: // if the status is 500 we return an internal server error message                            
                          toastr.error('Error: &lt;br /&gt;' +
                              errorResponse.data.exceptionMessage != null &amp;&amp; errorResponse.data.exceptionMessage.length &gt; 0 ? errorResponse.data.exceptionMessage : 
                              errorResponse.data.message, '');
                          break;
                      default: // for all other errors we display a default error message                            
                          toastr.error('Error ' + errorResponse.status + ': ' + errorResponse.data.message, '');
                  }
                  return $q.reject(errorResponse);
              });
          };
      });
  
      $compileProvider.directive('httpErrorMessages', function () {
          return {
              link: function (scope, element, attrs) {
                  elementsList.push($(element));
              }
          };
      });
  });
  </code></pre>