Angular 6 - http error status code 0 instead of 401, 400… any except 200

荒凉一梦 提交于 2019-12-08 04:00:27

问题


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.

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 ?

来源:https://stackoverflow.com/questions/53040293/angular-6-http-error-status-code-0-instead-of-401-400-any-except-200

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!