title: Angular interceptor - get message from 500 error
body: <p>I'm using an Angular Interceptor and I want to get the <strong>message</strong> from 500 errors (internal server error).</p>
  
  <p>The problem is, that I'm getting the whole HTML in the <strong>rejection.data</strong> in <strong>responseError</strong> inside Interceptor (screenshot below).</p>
  
  <p>I read that I have to configure <strong>web.config</strong> but I'm still getting the whole HTML. I just want to get the message.</p>
  
  <p>Is it possible to do that?</p>
  
  <p>Angular Interceptor:</p>
  
  <pre><code>app.config(['$httpProvider', function ($httpProvider) {
  
      $httpProvider.interceptors.push(function ($q, $rootScope) {
  
          return {
              request: function (config) {
  
                  //the same config / modified config / a new config needs to be returned.
                  return config;
              },
              requestError: function (rejection) {
  
                  //Initializing error list
                  if ($rootScope.errorList == undefined) {
                      $rootScope.errorList = [];
                  }
  
                  $rootScope.errorList.push(rejection.data);
  
                  //It has to return the rejection, simple reject call doesn't work
                  return $q.reject(rejection);
              },
              response: function (response) {
  
                  //the same response/modified/or a new one need to be returned.
                  return response;
              },
              responseError: function (rejection) {
  
                  //Initializing the error list
                  if ($rootScope.errorList == undefined) {
                      $rootScope.errorList = [];
                  }
  
                  //Adding to error list
                  $rootScope.errorList.push(rejection.data);
  
                  //It has to return the rejection, simple reject call doesn't work
                  return $q.reject(rejection);
              }
          };
      });
  }]);
  </code></pre>
  
  <p>Web.Config</p>
  
  <pre><code>&lt;system.webServer&gt;
      &lt;httpErrors existingResponse="PassThrough" errorMode="Detailed"&gt;&lt;/httpErrors&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/PVaR2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PVaR2.png" alt="Image"></a></p>
  
  <p>Edit:
  I want to get the Message from the exception snapshot</p>
  
  <p><a href="https://i.stack.imgur.com/yNABI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yNABI.png" alt="Image2"></a></p>