mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 22:27:55 +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) {
|
onFailure:function (xhr) {
|
||||||
console.log("onFailure....");
|
|
||||||
var responseText = xhr.responseText;
|
var responseText = xhr.responseText;
|
||||||
var error = null;
|
var userMsg = {severity:"ERROR", message:$msg('SAVE_COULD_NOT_BE_COMPLETED')};
|
||||||
|
|
||||||
var contentType = this.getHeader("Content-Type");
|
var contentType = this.getHeader("Content-Type");
|
||||||
if (contentType != null && contentType.indexOf("application/json") != -1) {
|
if (contentType != null && contentType.indexOf("application/json") != -1) {
|
||||||
|
var serverMsg = null;
|
||||||
try {
|
try {
|
||||||
error = JSON.decode(responseText);
|
serverMsg = JSON.decode(responseText);
|
||||||
events.onError(persistence._buildError(error));
|
serverMsg = serverMsg.globalSeverity ? serverMsg : null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
events.onError(persistence._buildError());
|
// Message could not be decoded ...
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
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"},
|
headers:{"Content-Type":"application/json", "Accept":"application/json"},
|
||||||
|
Loading…
Reference in New Issue
Block a user