Jul 12, 2010, 1:50 PM
[CLOSED] Global exception handling - wrong response or no failure
Hello guys,
since some time I encounter a very strange behaviour handling exceptions on client-side.
I have attached a demo project which illustrates my problem.
There are two buttons on the default page. If you click on the first button, an exception is being thrown within the assigned AjaxEvent. The second button does exactly the same, the only difference is that not an AjaxEvent but an AjaxMethod is invoked by the listener assigned which then throws an exception too.
What i want to achieve is that wherever (AjaxMethod, AjaxEvent or page event) an exception occurs a message dialog is going to be displayed on the user interface to inform the user about the exception. To display an easier to understand error dialog I`ve overriden Coolite`s one as suggested in several threads here. It displays full stack information if the project is built within debug mode otherwise it only displays the error message itself without any stack information.
A main goal is no need to implement any special behaviour needed to catch the exception and display it (like "Coolite.ScriptManager.Success = false" or such things).
While a click on the first button causes an unexpected response to be sent to the browser (plain Html instead of JSON including the error message), clicking on the second button returns the JSON data as expected, but the error dialog never gets displayed (success = false within response, but error event of Coolite is never invoked i think).
I have this problems with both FF 3 and IE 8 using Coolite 0.8.2.19471 from your repository. I know some time ago it worked perfectly.
If you can not reproduce this problems i will post some screenshots here.
Can you please give me any suggestions on this ?
Thank you !
Greets,
Peter
since some time I encounter a very strange behaviour handling exceptions on client-side.
I have attached a demo project which illustrates my problem.
There are two buttons on the default page. If you click on the first button, an exception is being thrown within the assigned AjaxEvent. The second button does exactly the same, the only difference is that not an AjaxEvent but an AjaxMethod is invoked by the listener assigned which then throws an exception too.
What i want to achieve is that wherever (AjaxMethod, AjaxEvent or page event) an exception occurs a message dialog is going to be displayed on the user interface to inform the user about the exception. To display an easier to understand error dialog I`ve overriden Coolite`s one as suggested in several threads here. It displays full stack information if the project is built within debug mode otherwise it only displays the error message itself without any stack information.
A main goal is no need to implement any special behaviour needed to catch the exception and display it (like "Coolite.ScriptManager.Success = false" or such things).
protected string GetExceptionHandlerScript(string onRequestFailureScript)
{
StringBuilder script = new StringBuilder();
// overriding default exception handler here (AjaxEvent, AjaxMethod and Server-side event) to display a custom "beautified" error dialog (with full exception stack if in debug mode otherwise only displaying plain error message)
script.Append(@"Coolite.AjaxEvent.override({
showFailure: function(response,errorMsg) {");
script.Append("alert('error');");
script.Append("if (Ext.isEmpty(errorMsg)) errorMsg = Ext.decode(response.responseText).errorMessage;");
script.Append("var stack0 = errorMsg.indexOf('\\r\\n');");
script.Append("var stack1 = errorMsg.length;");
script.Append("var desc0 = errorMsg.indexOf(':') + 1;");
script.Append("var desc1 = stack0;");
script.Append("Ext.Msg.show({");
script.Append("title: 'Error',");
script.Append("msg: errorMsg.substring(desc0, desc1),"); // error message
script.Append("value: errorMsg.substring(stack0, stack1).trim(),"); // display stack
script.Append("buttons: Ext.MessageBox.OK,");
#if (DEBUG)
script.Append("multiline: true,");
#else
script.Append("multiline: false,"); // ==> "value" textfield is hidden
#endif
script.Append("width: 500,");
script.Append("icon: Ext.MessageBox.ERROR");
script.Append("});");
if (!String.IsNullOrEmpty(onRequestFailureScript))
script.Append(onRequestFailureScript);
script.Append("return false;");
script.Append(@"}});");
return script.ToString();
}
[AjaxMethod]
public void ThrowExceptionMethod()
{
throw new Exception("test");
}
protected void ThrowExceptionEvent(object sender, AjaxEventArgs e)
{
throw new Exception("test");
}
However what happens is very strange.While a click on the first button causes an unexpected response to be sent to the browser (plain Html instead of JSON including the error message), clicking on the second button returns the JSON data as expected, but the error dialog never gets displayed (success = false within response, but error event of Coolite is never invoked i think).
I have this problems with both FF 3 and IE 8 using Coolite 0.8.2.19471 from your repository. I know some time ago it worked perfectly.
If you can not reproduce this problems i will post some screenshots here.
Can you please give me any suggestions on this ?
Thank you !
Greets,
Peter
Last edited by geoffrey.mcgill; Jul 13, 2010 at 5:35 PM.