Commit f83d572f authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Better exception handling

parent c1109ea4
......@@ -7,7 +7,7 @@ Ext.ux.ProgressFormPanel = function(config,submitAjaxConfig) {
// Check for submit message override
if (submitAjaxConfig && submitAjaxConfig.submitMsg) {
submitMsg = 'Logging in...';
submitMsg = submitAjaxConfig.submitMsg;
}
......@@ -25,6 +25,8 @@ Ext.ux.ProgressFormPanel = function(config,submitAjaxConfig) {
// Display failure message
actionfailed: { scope:this, fn:function(form, action){
var hideMe = 0;
var title;
var msg;
// We should hide the loadmask here
if ((action.type == 'load' || action.type == 'submit') && this.rendered == true) {
......@@ -36,22 +38,23 @@ Ext.ux.ProgressFormPanel = function(config,submitAjaxConfig) {
hideMe = 1;
}
printStr = '<b>Error: </b>';
// Check if we have result.msg
if (action.result && action.result.msg) {
printStr += action.result.msg;
title = "Transport Error: ";
msg = action.result.msg;
// Check if we have result.errors
} else if (action.result && action.result.errors) {
title = "Server Error: ";
// Check if we just have a error code
if (action.result.data && action.result.data.ErrorCode) {
printStr += "Code: "+action.result.data.ErrorCode+"<br />";
printStr += "Reason: "+action.result.data.ErrorReason+"<br />";
msg = action.result.data.ErrorReason+"<br />";
msg += "code: "+action.result.data.ErrorCode;
// Add all errors
} else {
for (var i = 0; i < action.result.errors.length; i++) {
printStr += action.result.errors[i] + '<br />';
msg += '<br />' + action.result.errors[i];
}
}
......@@ -62,21 +65,27 @@ Ext.ux.ProgressFormPanel = function(config,submitAjaxConfig) {
isset(action.result.data.ErrorCode) &&
isset(action.result.data.ErrorReason)
) {
printStr = action.result.data.ErrorReason+"<br/>code:"+action.result.data.ErrorCode;
title = "Server Error: ";
msg = 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;
if (action.response.status) {
title = "Server Error: ";
}
msg = action.response.statusText + " (" + action.response.status + ")" ;
// Unknown
} else {
printStr += 'UNKNOWN ERROR: '+action.failureType;
title = "Unknown Error: ";
msg = 'Unknown Error: '+ action.failureType;
}
// Display error
Ext.Msg.show({
title: "Data Load Exception: ",
msg: printStr,
title: title,
msg: msg,
icon: Ext.MessageBox.ERROR,
modal: true,
buttons: Ext.Msg.CANCEL,
......
function storeException(requestConfig, storeObj, xmlEr, except) {
/*
Generic classes and customizations to extjs
Copyright (C) 2008-2010, AllWorldIT
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++) {
printStr += xmlEr.response.errors[i] + '<br />';
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
function storeException(proxy, type, action, options, response, arg) {
var msg;
var title;
// Server did not return HTTP 200 result
if (type == 'response') {
title = 'Transport Error: ';
// Check if we have server status
if (response.status) {
title = 'Server Error: ';
}
msg = response.statusText + ' (' + response.status + ')' ;
// Server replied with HTTP 200, but successProperty is false
} else if (type == 'remote') {
title = 'Server Error: ';
if (!isset(response.result)) {
msg = 'No result returned';
// Check success property is defined
} else if (!isset(response.success)) {
msg = 'Server didn\'t return success';
// Check if the request actually succeeded
} else if (response.success != false) {
msg = 'Server returned success';
// We should have a data attribute
} else if (!isset(response.data)) {
msg = 'Invalid response data';
// Make sure we have the error
} else if (!isset(response.data.ErrorCode) || !isset(response.data.ErrorReason)) {
msg = 'No error data returned';
} else {
msg = response.data.ErrorReason+'<br/>code:'+response.data.ErrorCode;
}
} else {
// add response text
printStr += '<b>Response:</b><br />'+xmlEr.responseText;
title = 'Unknown Error: ';
msg = 'Unknown error';
}
Ext.Msg.show({
title: "Data Load Exception: ",
msg: printStr,
title: title,
msg: msg,
icon: Ext.MessageBox.ERROR
});
}
......@@ -23,7 +79,6 @@ function storeException(requestConfig, storeObj, xmlEr, except) {
// Generic jason store
Ext.ux.JsonStore = function(config) {
config = Ext.apply({
......@@ -163,8 +218,6 @@ Ext.ux.GenericGridWindow = function(windowConfig,gridConfig,storeConfig,filtersC
}, storeConfig);
var store = new Ext.ux.JsonStore(storeConfig);
store.on('exception', storeException);
// Setup filters for the grid
var filters = new Ext.ux.grid.GridFilters(filtersConfig);
......@@ -223,9 +276,9 @@ Ext.ux.GenericGridWindow = function(windowConfig,gridConfig,storeConfig,filtersC
// Store handling
store.on('beforeload', function() { var win = Ext.getCmp(windowID); win.getEl().mask("Loading..."); } );
store.on('load', function() { var win = Ext.getCmp(windowID); win.getEl().unmask(); } );
store.on('exception', function(thisobj, action, rs, params) {
store.on('exception', function(thisobj, type, action, options, response, arg) {
var win = Ext.getCmp(windowID); win.getEl().unmask();
storeException(thisobj,action,rs,params);
storeException(thisobj,type,action,options,response,arg);
});
// Apply our own window configuration
......@@ -359,12 +412,12 @@ uxAjaxRequest = function(theWindow,config) {
// Check what kind of error we got
if (isset(response.responseText)) {
// Connection related
title = "Connection error: ";
title = "Transport Error: ";
msg = response.responseText;
// Backend related
} else if (isset(response.ErrorCode) && isset(response.ErrorReason)) {
title = "Error: ";
title = "Server Error: ";
msg = response.ErrorReason+"<br/>code:"+response.ErrorCode;
} else {
title = "Unknown Error";
......
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