title: Handling errors on 200 HTTP response using interceptors
body: <p>I have service that integrates with external API. This API is inconsistent and it is unlikely to change.</p>
  
  <p>Inside API there are 2 methods of reporting error, one is response with HTTP 500 code, other is normal 200 HTTP reponse, but with <code>status</code> in JSON set to "error". </p>
  
  <p>Handling 500 error is working fine, I have just created interceptor (ngResource interceptor, not $http one) with <code>responseError</code> method that will display error message to user when there is any 500 response from API:</p>
  
  <pre><code>.factory('ApiErrorHandling', ['ngDialog', function(ngDialog) {
      return {
          responseError: function(response) {
              console.log(response);
              var error_dialog = ngDialog.open({
                  template: '/api/error.html',
                  className: 'error',
                  preCloseCallback: function() {
                      if (response.data.status == 'fatal') {
                          window.location.href = '/';
                      } else if (response.data.status == 'error') {
                          var dialogs = ngDialog.getOpenDialogs();
                          for (var i in dialogs) {
                              var dialog = dialogs[i];
                              if (dialog != error_dialog.id) {
                                  ngDialog.close(dialog);
                              }
                          }
                      }
                  },
                  data: {
                      code: response.data.code,
                      status: response.data.status,
                      message: response.data.message,
                      httpCode: response.status,
                  }
              });
          },
      }
  }])
  .factory('ApiMethod', ['$resource', 'ApiErrorHandling', function($resource, ApiErrorHandling) {
      return $resource('/api/method/', {}, {
              query: {method:'POST', interceptor: ApiErrorHandling},
      });
  }])
  </code></pre>
  
  <p>But I have problem with handling error responses with <code>status</code>. I don't want normal success callback (passed into method from resource instance) to be called when error occurs, I want one global error handler, but nothing I've tried so far worked. Each time response is passed into callback. I've tried so far:</p>
  
  <ul>
  <li>returning $q.reject in <code>response</code> method from interceptor</li>
  <li>changing status code in response to 500 inside <code>response</code> method from interceptor</li>
  <li>changing or deleting response.resource in <code>response</code> method from interceptor</li>
  </ul>
  
  <p>Ideal solution will be when normal callback won't be called, but my <code>responseError</code> method from interceptor will be called instead.</p>