ui: deal better with unexpected non JSON responses

Change-Id: Ieacac4dc734421743ca30bf79b0f3afdbbe00892
This commit is contained in:
mpl 2013-08-11 19:56:31 +02:00
parent 9fcb4b6434
commit 489c78746b
1 changed files with 12 additions and 2 deletions

View File

@ -110,7 +110,15 @@ function(success, fail, e) {
var error = !xhr.isSuccess();
var result = null;
if (!error) {
result = xhr.getResponseJson();
try {
result = xhr.getResponseJson();
} catch(err) {
console.log("Response was not valid JSON: " + xhr.getResponseText());
if (fail) {
fail();
}
return;
}
error = !result;
}
if (error) {
@ -154,7 +162,9 @@ function(success, opt_fail) {
this.sendXhr_(path,
goog.bind(this.handleXhrResponseJson_, this,
success, this.safeFail_(opt_fail)
success, function(msg) {
console.log("serverStatus error: " + msg);
}
)
);
};