X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/dbd31e1486a3f2a94cb6828ee5ceb7dee783091f..ce89530aa0db752e169adb914938d7f5f9f0ed5a:/platforma/static/js/app.js?ds=inline 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;