X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/3193141f55df20910cf8ba35f9e669d79c90d3f4..2fc23bdb4ec0198ab47ce73e7b5287375ae68a12:/platforma/static/js/app.js?ds=sidebyside
diff --git a/platforma/static/js/app.js b/platforma/static/js/app.js
index e8b439df..e870a387 100644
--- a/platforma/static/js/app.js
+++ b/platforma/static/js/app.js
@@ -183,23 +183,54 @@ Editor.Object = Class.extend({
// Handle JSON error responses in uniform way
function parseXHRError(response)
{
- var message = ""
+ var message = "";
+ var level = "";
+
try {
var json = $.evalJSON(response.responseText);
if(json.reason == 'xml-parse-error') {
- message = json_response.message.replace(/(line\s+)(\d+)(\s+)/i,
+ message = json.message.replace(/(line\s+)(\d+)(\s+)/i,
"$1$2$3");
message = message.replace(/(line\s+)(\d+)(\,\s*column\s+)(\d+)/i,
"$1$2$3$4");
+
+ level = "warning";
+ }
+ else if(json.reason == 'xml-non-valid') {
+ message = json.message;
+ level = "warning";
+ }
+ else {
+ message = json.message || json.reason || "Nieznany bÅÄ
d :((";
+ level = "error";
}
- message = json_response.message || json_response.reason || "Nieznany bÅÄ
d :((";
} catch(e) {
// not a valid JSON response
- message = response.statusText;
+ message = response.statusText || 'Brak poÅÄ
czenia z serwerem';
+ level = "error";
}
- return message;
+
+ return {error_message: message, error_level: level};
+}
+
+function parseXHRResponse(xhr) {
+ var response = {}
+
+ if(xhr.status >= 200 && xhr.status < 300)
+ {
+ response.success = true;
+ try {
+ response.data = $.evalJSON(xhr.responseText);
+ } catch(e) {
+ response.data = {};
+ }
+
+ return response;
+ }
+
+ return parseXHRError(xhr);
}
Editor.Object._lastGuid = 0;