Handle AJAX errors when updating content

With the change in implementation in the previous commit, any error
(eg server responds with `500`) would cause the page to not be updated
again.

This is better than the previous implementation, whereby the browser
would re-request as fast as it could until it got a successful response.

This commit handles errors by clearing the render queue if the server
returns an error. So:

- Any updates that would have been performed based on this request are
  dropped
- Subsequent updates will be attempted as if it was the first load of
  the page, ie after a delay of `x` seconds
This commit is contained in:
Chris Hill-Scott
2016-06-12 08:40:56 +01:00
parent 9c92a2bd86
commit 940170159a

View File

@@ -17,11 +17,16 @@
while(queue.length) queue.shift()(response);
};
var clearQueue = queue => (queue.length = 0);
var poll = function(renderer, resource, queue, interval) {
if (queue.push(renderer) === 1) $.get(
resource,
if (queue.push(renderer) === 1) $.ajax(
resource
).done(
response => flushQueue(queue, response)
).fail(
() => clearQueue(queue)
);
setTimeout(