Error handling on request processing

This commit is contained in:
Jonathan Putney
2019-11-19 13:58:29 -05:00
parent cd4af37775
commit a23cf5557b
4 changed files with 16 additions and 8 deletions

View File

@@ -864,10 +864,10 @@ export default class BaseAPI {
processHttpRequest(url: String, params) {
const httpReq = new XMLHttpRequest();
httpReq.open('POST', url, false);
httpReq.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
try {
if (params instanceof Array) {
httpReq.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
httpReq.send(params.join('&'));
} else {
httpReq.send(params);
@@ -879,7 +879,11 @@ export default class BaseAPI {
};
}
return JSON.parse(httpReq.responseText);
try {
return JSON.parse(httpReq.responseText);
} catch (e) {
return {};
}
}
/**