From 5d802ba9f9e4604a8434ce298b1d9a0135921645 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 2 Oct 2020 19:43:36 -0700 Subject: [PATCH] Let response status be 0 even if request didn't complete. Since meta.status would be undefined for an incomplete request, I would have to check response.completed && response.meta.status, which is too much burden. Let's set the status immediately, and if a callback wants to do further diving we'll use completed then. --- frontends/etiquette_flask/static/js/common.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/etiquette_flask/static/js/common.js b/frontends/etiquette_flask/static/js/common.js index 4e1fc98..31e2f2f 100644 --- a/frontends/etiquette_flask/static/js/common.js +++ b/frontends/etiquette_flask/static/js/common.js @@ -8,6 +8,7 @@ function _request(method, url, callback) const request = new XMLHttpRequest(); const response = { "completed": false, + "meta": {"status": 0}, }; request.onreadystatechange = function() @@ -18,10 +19,9 @@ function _request(method, url, callback) if (callback == null) {return;} - response.meta = { - "request_url": url, - "status": request.status - } + response.meta.status = request.status; + response.meta.request_url = url; + if (request.status != 0) { response.completed = true;