简体   繁体   中英

Difference in behaviour between HTTP Status code 410 and other codes w.r.t Angular 5

Backend: Java

Frontend: Angular 5

Consider this:

The frontend makes an HTTP request to the backend.

The backend returns an HTTP Status code as response to the frontend's request.

For error-handling testing, I change the HTTP code, returned from the backend, manually.

Scenario 1:

On setting the code-to-be-returned to FORBIDDEN (407), the frontend correctly displayed the 407 error. Now, on setting back the code to OK (200), the frontend correctly reflected that as well.

Scenario 2:

On setting the code-to-be-returned to GONE (410), the frontend correctly displayed the 410 error. However, on setting back the code to OK (200), the frontend did not correctly reflect the change, but continued to show error 410.

In fact, even after stopping the server, the frontend did not show a net::ERR_CONNECTION_REFUSED error, but continued to show the 410.

Any explanations?

Be careful when using HTTP response status 410 , since it will be cached in browser for indicating that the target resource is no longer available from the original server and will not be available again .(this is decided by server side). See details .

Because it's server side who determine the expired period when response with 410 , so browser will simply cache it, and next time you try to request for the same resource, browser won't fire a request until it's expired. This can help for preventing useless requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM