Angular 6 - http error status code 0 instead of 40

2019-06-04 05:46发布

I know similar solution already given by many enthusiastic over here, Link-1 Link-2

But I already configured CORS. so I am using NGiNX server and see following configuration in order to satisfied CORS issue...

if ($request_method = 'OPTIONS') {
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'Location,DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'Origin, X-Requested-With, X-AUTH-TOKEN, Content-Type, Accept, Authorization, Location, Cache-Control, User-Agent, Keep-Alive';
      add_header 'Access-Control-Max-Age' 1728000;
      add_header 'Content-Type' 'text/plain charset=UTF-8';
      add_header 'Content-Length' 0;
      return 204;
}
if ($request_method = 'POST') {
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'Origin, X-Requested-With, X-AUTH-TOKEN, Content-Type, Accept, Authorization, Location, Cache-Control, User-Agent, Keep-Alive';
}
if ($request_method = 'GET') {
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'Origin, X-Requested-With, X-AUTH-TOKEN, Content-Type, Accept, Authorization, Location, Cache-Control, User-Agent, Keep-Alive';
} 

See below screen-shot, which is I have captured from my browser(Chrome)'s console in order to highlight it to you all. enter image description here

Why Angular is not able to capture status code 401(or any except 200) correctly. it's every time giving "0" instead of valid one.

NOTE - few time back it was working correctly. so I guess CORS settings are correctly handled. that's why I guess not sure what's wrong going on.

Any Help would really appreciable !!

UPDATE - As per this link they are recommending to add " WWW-Authenticate" Header. is it required ? due to this only it's causing me my current issue ?

0条回答
登录 后发表回答