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
+7 -3
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+7 -3
View File
@@ -864,10 +864,10 @@ export default class BaseAPI {
processHttpRequest(url: String, params) { processHttpRequest(url: String, params) {
const httpReq = new XMLHttpRequest(); const httpReq = new XMLHttpRequest();
httpReq.open('POST', url, false); httpReq.open('POST', url, false);
httpReq.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
try { try {
if (params instanceof Array) { if (params instanceof Array) {
httpReq.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
httpReq.send(params.join('&')); httpReq.send(params.join('&'));
} else { } else {
httpReq.send(params); 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 {};
}
} }
/** /**