From 79db3f6c19eb32f54ea293b5948ad9f44018968c Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 16 Mar 2011 12:13:08 +0100 Subject: [PATCH] improved exception handling in frontend --- htdocs/frontend/javascripts/functions.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/htdocs/frontend/javascripts/functions.js b/htdocs/frontend/javascripts/functions.js index 78ee485..472cde3 100644 --- a/htdocs/frontend/javascripts/functions.js +++ b/htdocs/frontend/javascripts/functions.js @@ -32,8 +32,20 @@ vz.load = function(args) { url: this.options.backendUrl, dataType: 'json', error: function(xhr) { - json = JSON.parse(xhr.responseText); - vz.wui.dialogs.error(xhr.statusText, json.exception.message, xhr.status); + try { + if (xhr.getResponseHeader('Content-type') == 'application/json') { + var json = JSON.parse(xhr.responseText); + + if (json.exception) { + throw new Exception(json.exception.type, json.exception.message, (json.exception.code) ? json.exception.code : xhr.status); + } + } + + throw new Exception(xhr.statusText, 'Unknown backend response', xhr.status) + } + catch (e) { + vz.wui.dialogs.exception(e); + } } });