mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
Improve error handling ...
This commit is contained in:
parent
3f2f23d3c1
commit
751692837c
@ -63,27 +63,30 @@ mindplot.RESTPersistenceManager = new Class({
|
||||
},
|
||||
|
||||
onFailure:function (xhr) {
|
||||
console.log("onFailure....");
|
||||
|
||||
var responseText = xhr.responseText;
|
||||
var error = null;
|
||||
var userMsg = {severity:"ERROR", message:$msg('SAVE_COULD_NOT_BE_COMPLETED')};
|
||||
|
||||
var contentType = this.getHeader("Content-Type");
|
||||
if (contentType != null && contentType.indexOf("application/json") != -1) {
|
||||
var serverMsg = null;
|
||||
try {
|
||||
error = JSON.decode(responseText);
|
||||
events.onError(persistence._buildError(error));
|
||||
serverMsg = JSON.decode(responseText);
|
||||
serverMsg = serverMsg.globalSeverity ? serverMsg : null;
|
||||
} catch (e) {
|
||||
events.onError(persistence._buildError());
|
||||
throw new Error("Unexpected error saving. Error response is not json object:" + responseText);
|
||||
}
|
||||
} else {
|
||||
var msg = {severity:"ERROR", message:$msg('SAVE_COULD_NOT_BE_COMPLETED')};
|
||||
if (this.status == 405) {
|
||||
msg = {severity:"ERROR", message:$msg('SESSION_EXPIRED')};
|
||||
}
|
||||
events.onError(msg);
|
||||
// Message could not be decoded ...
|
||||
}
|
||||
userMsg = persistence._buildError(serverMsg);
|
||||
|
||||
} else {
|
||||
if (this.status == 405) {
|
||||
userMsg = {severity:"ERROR", message:$msg('SESSION_EXPIRED')};
|
||||
}
|
||||
}
|
||||
events.onError(userMsg);
|
||||
|
||||
// Only for debug. Remove.
|
||||
throw new Error("responseText:" + responseText + ",status:" + this.status);
|
||||
},
|
||||
|
||||
headers:{"Content-Type":"application/json", "Accept":"application/json"},
|
||||
|
Loading…
Reference in New Issue
Block a user