0

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?

rahs
  • 1,759
  • 2
  • 15
  • 31

1 Answers1

4

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.

Pengyy
  • 37,383
  • 15
  • 83
  • 73
  • Thanks! The first time this happened, it got resolved in a few minutes. However, now the 410 error is still being displayed (since a long time). Will clearing the browser's cache solve this? Is there any other method to solve it? – rahs Apr 27 '18 at 10:39
  • @RahulSaha I think you should response with **404** instead if the resource is not absolutely dead. – Pengyy Apr 27 '18 at 10:41
  • @RahulSaha have you tried restart your angular app and also maybe you also need to clear browser cache and restart the browser. – Pengyy Apr 27 '18 at 10:51
  • Clearing the cache worked! (Aside, I cleared the cache from chrome, but it did not reflect in my local folder, C:\Users\u1\AppData\Local\Google\Chrome\User Data\Default\Cache, - any idea why)? – rahs Apr 27 '18 at 10:59
  • Good anwser Sir ! – Abdo Bmz Apr 27 '18 at 19:20
  • I tried to solved it with `Cache-Control: no-cache` response header, but it did not work, use `no-store` instead; – Sh Svyatoslav May 26 '20 at 14:39