mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 00:20:43 -04:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user