Catch json parse errors, setting json_ok = false.

This commit is contained in:
voussoir 2020-09-15 23:10:35 -07:00
parent fbb373c37e
commit 1af8342202

View file

@ -18,15 +18,23 @@ function _request(method, url, callback)
if (callback == null)
{return;}
if (request.status != 0)
{
response.completed = true;
response.data = JSON.parse(request.responseText);
}
response.meta = {
"request_url": url,
"status": request.status
}
if (request.status != 0)
{
response.completed = true;
try
{
response.data = JSON.parse(request.responseText);
response.meta.json_ok = true;
}
catch (exc)
{
response.meta.json_ok = false;
}
}
callback(response);
};
const asynchronous = true;