X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/cf265108541da0a0f54e2b4517ce9441e8ccf795..198be737937aec7259e81ba791bf7f4e401795eb:/platforma/static/js/app.js?ds=sidebyside diff --git a/platforma/static/js/app.js b/platforma/static/js/app.js index 8dae56e4..e870a387 100644 --- a/platforma/static/js/app.js +++ b/platforma/static/js/app.js @@ -183,7 +183,9 @@ 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); @@ -193,16 +195,42 @@ function parseXHRError(response) 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 :(("; + message = json.message || json.reason || "Nieznany błąd :(("; + level = "error"; } - } 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;