title: Unable to get correct exception message Angular + spring boot
body: <p>I have an application written in Angular 8 and APIs in spring boot ..</p>
  <p>When I am calling the APIs from HttpClient in Angular, the API is returning the response correctly however if there is any exception during the API call , the angular is not able to get the correct exception message .. However, when I am calling the same API from postman, I am able to get the correct exception message ..</p>
  <p>Expected exception message ( as received in postman ):</p>
  <pre><code>{
      &quot;timestamp&quot;: &quot;2022-03-24T19:00:45.910+0000&quot;,
      &quot;status&quot;: 500,
      &quot;error&quot;: &quot;Internal Server Error&quot;,
      &quot;message&quot;: &quot;Resource not in ready state&quot;,
      &quot;path&quot;: &quot;/v1/app/rest/api/url&quot;
      }
  </code></pre>
  <p>Unexpected Exception message received in angular:</p>
  <pre><code>{
    &quot;headers&quot;: {
      &quot;normalizedNames&quot;: {},
      &quot;lazyUpdate&quot;: null,
      &quot;headers&quot;: {}
    },
    &quot;status&quot;: 0,
    &quot;statusText&quot;: &quot;Unknown Error&quot;,
    &quot;url&quot;: &quot;/v1/app/rest/api/url&quot;,
    &quot;ok&quot;: false,
    &quot;name&quot;: &quot;HttpErrorResponse&quot;,
    &quot;message&quot;: &quot;Http failure response for /v1/app/rest/api/url: 0 Unknown Error&quot;,
    &quot;error&quot;: {
      &quot;isTrusted&quot;: true
    }
  }
  </code></pre>
  <p>I am also seeing this message in the console when any exception happens</p>
  <p><strong>Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at <a href="https://fakeurl.com/v1/app/rest/api/url" rel="nofollow noreferrer">https://fakeurl.com/v1/app/rest/api/url</a>. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 500.</strong></p>
  <p>However, this message is thrown in console only when there is an exception</p>
  <p>I have already added the Cors setting</p>
  <pre><code>CorsConfiguration config = new CorsConfiguration();
          config.setAllowCredentials(true);
          config.addAllowedOrigin(&quot;*&quot;);
          config.addAllowedHeader(&quot;*&quot;);
          config.addAllowedMethod(&quot;OPTIONS&quot;);
          config.addAllowedMethod(&quot;HEAD&quot;);
          config.addAllowedMethod(&quot;GET&quot;);
          config.addAllowedMethod(&quot;PUT&quot;);
          config.addAllowedMethod(&quot;POST&quot;);
          config.addAllowedMethod(&quot;DELETE&quot;);
          config.addAllowedMethod(&quot;PATCH&quot;);
  </code></pre>
  <p>Angular code</p>
  <pre><code>
  this.subscription = this.myService.myApi()
      .subscribe(
        (response) =&gt;{
  
           console.log(response)
        },
        (error) =&gt;{
          console.log(error)
  
        }
      );
  
  </code></pre>
  <p>CORS configuration in project</p>
  <pre><code>
  import org.springframework.context.annotation.Configuration;
  import org.springframework.security.config.annotation.web.builders.WebSecurity;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  
  @Configuration
  public class ApplicationSecurity extends WebSecurityConfigurerAdapter {
      @Override
      public void configure(WebSecurity web) throws Exception {
          web.ignoring().antMatchers(&quot;/**&quot;);
      }
  }
  
  </code></pre>
  <pre><code>
  import org.springframework.boot.web.servlet.FilterRegistrationBean;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.cors.CorsConfiguration;
  import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
  import org.springframework.web.filter.CorsFilter;
  
  
  @Configuration
  public class CorsWebConfiguration {
      
      @Bean
      public FilterRegistrationBean&lt;CorsFilter&gt; corsFilter() {
          UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
          CorsConfiguration config = new CorsConfiguration();
          config.setAllowCredentials(true);
          config.addAllowedOrigin(&quot;*&quot;);
          config.addAllowedHeader(&quot;*&quot;);
          config.addAllowedMethod(&quot;OPTIONS&quot;);
          config.addAllowedMethod(&quot;HEAD&quot;);
          config.addAllowedMethod(&quot;GET&quot;);
          config.addAllowedMethod(&quot;PUT&quot;);
          config.addAllowedMethod(&quot;POST&quot;);
          config.addAllowedMethod(&quot;DELETE&quot;);
          config.addAllowedMethod(&quot;PATCH&quot;);
          source.registerCorsConfiguration(&quot;/**&quot;, config);
          final FilterRegistrationBean&lt;CorsFilter&gt; bean = new FilterRegistrationBean&lt;CorsFilter&gt;(new CorsFilter(source));
          bean.setOrder(0);
          return bean;
      }
  }
  </code></pre>