Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

angular - NGiNX - Not returning sufficient headers for error(4xx, 5xx) Vs Success(2xx)

Hello Friends,

I have independently ask a question in the same context but from angular perspective.

Kindly refer my NGiNX server configuration .

What I am phasing is, whenever my Angular app's REST request successfully(200) returns from server(where NGiNX installed) in such a case NGiNX returns sufficient headers along with response & I am able to successfully handle it Vs Error request/response.

Especial case is, I am unable to get request status. For example, if my API return 401, 400, 500.. except 200 in such a case my angular App is getting http response-status as a "Zero(0)" irrespective of what server returns. My main assumption is due to either CORS issue(which is mainly all recommending to fix) or some hidden(for me).

In Angular I am able to see below things(refer screen-shot), enter image description here

My assumption is, if CORS issue then my 200 request response must also not server. so my guess is CORS I have configured correctly.

Any Help would be really appreciate in advanced!

NOTE -

  1. I am confuse whether it's NGiNX side an issue or Angular side. that's why I ask the same question under different tags(Angular, Nginx).
  2. I have also implemented SSL at server side. so kindly consider this case as well.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To add headers to 4xx and 5xx errors: When setting the headers, you must use the always param:

add_header <header_name> <value> always

See the docs at http://nginx.org/en/docs/http/ngx_http_headers_module.html#add_header:

Adds the specified field to a response header provided that the response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304, 307 (1.1.16, 1.0.13), or 308 (1.13.0)… If the always parameter is specified (1.7.5), the header field will be added regardless of the response code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...