Commit 13171ed2 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Greatly improved error handling

parent 8c5d1778
......@@ -55,14 +55,19 @@ Ext.ux.ProgressFormPanel = function(config,submitAjaxConfig) {
}
}
// Check if we just have a result
} else if (
isset(action.result) &&
isset(action.result.data) &&
isset(action.result.data.ErrorCode) &&
isset(action.result.data.ErrorReason)
) {
printStr = action.result.data.ErrorReason+"<br/>code:"+action.result.data.ErrorCode;
// Check if we have an action response
} else if (action.response) {
printStr += action.response.responseText;
// Check if we just have a result
} else if (action.result) {
printStr += action.result;
// Unknown
} else {
printStr += 'UNKNOWN ERROR: '+action.failureType;
......@@ -70,7 +75,7 @@ Ext.ux.ProgressFormPanel = function(config,submitAjaxConfig) {
// Display error
Ext.Msg.show({
title: "Exception occured: ",
title: "Data Load Exception: ",
msg: printStr,
icon: Ext.MessageBox.ERROR,
modal: true,
......
// FIXME
function storeLoadException(requestConfig, storeObj, xmlEr, except) {
/*
printStr = 'An exception occured while trying to load data.<br /><br /><br />';
printStr += '<b>Exception:</b> '+except.toString()+'<br />';
// add http status description
printStr += '<b>Service:</b> '+storeObj.url+'<br />';
printStr += '<b>Status:</b> '+xmlEr.status+' - '+xmlEr.statusText+'<br />';
*/
if (xmlEr.response && xmlEr.response.errors) {
if (isset(xmlEr.response) && isset(xmlEr.response.errors)) {
// If this is a return object with errors, display them...
printStr += '<b>Response:</b>';
for (var i = 0; i < xmlEr.response.errors.length; i++) {
......@@ -20,7 +14,7 @@ function storeLoadException(requestConfig, storeObj, xmlEr, except) {
}
Ext.Msg.show({
title: "Exception occured: ",
title: "Data Load Exception: ",
msg: printStr,
icon: Ext.MessageBox.ERROR
});
......@@ -261,6 +255,19 @@ Ext.extend(Ext.ux.GenericGridWindow, Ext.Window, {
function getJsonAccessor(expr) {
var re = /[\[\.]/;
return function(expr) {
try {
return(re.test(expr)) ?
new Function("obj", "return obj." + expr) :
function(obj){
return obj[expr];
};
} catch(e){}
return Ext.emptyFn;
};
};
// Generic ajax request
uxAjaxRequest = function(theWindow,config) {
......@@ -270,6 +277,58 @@ uxAjaxRequest = function(theWindow,config) {
// Success function
success: function(response,options) {
var result;
// Try decode response, if we can't throw exception
try {
result = Ext.decode(response.responseText);
} catch(e) {
if (options.failure) {
options.failure.call(options.scope, response, options);
}
if (options.callback) {
options.callback.call(options.scope, options, false, response);
}
return;
}
// Check success property is defined
if (!isset(result.success)) {
if (options.failure) {
options.failure.call(options.scope, response, options);
}
if (options.callback) {
options.callback.call(options.scope, options, false, response);
}
return;
}
// Check if the request actually succeeded
if (result.success == false) {
var myResponse;
// We should have a data attribute
if (!isset(result.data)) {
myResponse = response;
// Make sure we have the error
} else if (!isset(result.data.ErrorCode) || !isset(result.data.ErrorReason)) {
myResponse = response;
// We have everything we need
} else {
myResponse = result.data;
}
if (options.failure) {
options.failure.call(options.scope, myResponse, options);
}
if (options.callback) {
options.callback.call(options.scope, options, false, myResponse);
}
return;
}
// if we have a custom success function, run it
if (config.customSuccess) {
config.customSuccess(response,options);
......@@ -282,9 +341,27 @@ uxAjaxRequest = function(theWindow,config) {
// Failure function
failure: function(response,options) {
var title;
var msg;
// Check what kind of error we got
if (isset(response.responseText)) {
// Connection related
title = "Connection error: ";
msg = response.responseText;
// Backend related
} else if (isset(response.ErrorCode) && isset(response.ErrorReason)) {
title = "Error: ";
msg = response.ErrorReason+"<br/>code:"+response.ErrorCode;
} else {
title = "Unknown Error";
msg = "Unknown Error";
}
Ext.Msg.show({
title: "Exception occured:",
msg: response.responseText,
title: title,
msg: msg,
icon: Ext.MessageBox.ERROR,
fn: function() {
if (theWindow) {
......@@ -299,3 +376,4 @@ uxAjaxRequest = function(theWindow,config) {
}
// vim: ts=4
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment