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:
parent
94e3bcd21d
commit
ed3942b943
1 changed files with 4 additions and 4 deletions
|
@ -8,6 +8,7 @@ function _request(method, url, callback)
|
||||||
const request = new XMLHttpRequest();
|
const request = new XMLHttpRequest();
|
||||||
const response = {
|
const response = {
|
||||||
"completed": false,
|
"completed": false,
|
||||||
|
"meta": {"status": 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
request.onreadystatechange = function()
|
request.onreadystatechange = function()
|
||||||
|
@ -18,10 +19,9 @@ function _request(method, url, callback)
|
||||||
if (callback == null)
|
if (callback == null)
|
||||||
{return;}
|
{return;}
|
||||||
|
|
||||||
response.meta = {
|
response.meta.status = request.status;
|
||||||
"request_url": url,
|
response.meta.request_url = url;
|
||||||
"status": request.status
|
|
||||||
}
|
|
||||||
if (request.status != 0)
|
if (request.status != 0)
|
||||||
{
|
{
|
||||||
response.completed = true;
|
response.completed = true;
|
||||||
|
|
Loading…
Reference in a new issue