Handling JSON exception.
This commit is contained in:
parent
1b0541a7b5
commit
6452a0c7f4
1 changed files with 10 additions and 8 deletions
|
|
@ -23,15 +23,17 @@ var ShapeShift = (function() {
|
||||||
if (xmlhttp.status == 200) {
|
if (xmlhttp.status == 200) {
|
||||||
var parsedResponse = JP(xmlhttp.responseText);
|
var parsedResponse = JP(xmlhttp.responseText);
|
||||||
cb.apply(null, [parsedResponse]);
|
cb.apply(null, [parsedResponse]);
|
||||||
} else if (xmlhttp.status === 500) {
|
|
||||||
var parsedResponse = JP(xmlhttp.responseText);
|
|
||||||
if (typeof parsedResponse.error === 'string') {
|
|
||||||
cb.apply(null, [parsedResponse]);
|
|
||||||
} else {
|
|
||||||
cb.apply(null, [new Error('Request Failed')]);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
cb.apply(null, [new Error('Request Failed')])
|
var cbResponse = new Error('Request Failed');
|
||||||
|
if (xmlhttp.status === 500) {
|
||||||
|
try {
|
||||||
|
var errorResponse = JSON.parse(xmlhttp.responseText);
|
||||||
|
if (typeof errorResponse.error === 'string') {
|
||||||
|
cbResponse = errorResponse;
|
||||||
|
}
|
||||||
|
} catch (e) { /* nop */ }
|
||||||
|
}
|
||||||
|
cb.apply(null, [cbResponse]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue