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.
This commit is contained in:
voussoir 2020-10-02 19:43:36 -07:00
parent d15d5f9856
commit 5d802ba9f9

View file

@ -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;