goodeggs / angular-cached-resource

An AngularJS module to interact with RESTful resources, even when browser is offline

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling error responses from the server

FreakTheMighty opened this issue · comments

What is the correct way to handle a 500 response with a cached resource? Currently, each time the client loads the request is retried. The error is due to invalid form data, so no amount of retrying will help the situation. My best guess for how to handle this is to delete the cached write request on 500 response.

Hey @FreakTheMighty, thanks for the feedback.

Our current thinking is that cached resource should give up on a 4xx response, but that it should keep trying on a 5xx response.

If the error is client-side (4xx), it should give up because theoretically something about the request needs to change before the request will work.

On the other hand, if the error is server-side (5xx), it should keep trying because theoretically whatever is wrong with the server might be fixed the next time the request is made.

There are problems with this theory. For example, if the client is a guest on a public wifi network that requires authentication of some sort, all GET requests often get redirected to a login page but POST requests get 4xx errors. (We definitely don't want the requests to get dropped in this case!)

In your specific case, would it be difficult to configure your server to return a 4xx exception when the client sends invalid form data? That'd be the canonical response in that case.

If there was a way to change the behavior of angular cached resource when the server sends back error codes, how would/should that look?

@demands I was able to change the status code and life is now good. These are pretty interesting problems! Thanks for the help.