Add error handling to synchronous methods (obligatory warning against using synchronous calls at all).

This commit is contained in:
Tim Coulter 2015-05-05 09:56:56 -07:00
parent b064eaba20
commit 2ca4240bb7
1 changed files with 10 additions and 1 deletions

View File

@ -48,7 +48,16 @@ HttpProvider.prototype.send = function (payload) {
//if (request.status !== 200) { //if (request.status !== 200) {
//return; //return;
//} //}
return JSON.parse(request.responseText);
var result = request.responseText;
try {
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(result);
}
return result;
}; };
HttpProvider.prototype.sendAsync = function (payload, callback) { HttpProvider.prototype.sendAsync = function (payload, callback) {