PDA

View Full Version : [CLOSED] Problem when trying to show an error captured by the loader Listener named 'Exception'.



RCN
Jun 21, 2012, 7:56 PM

Daniil
Jun 21, 2012, 9:11 PM
Hi,

Well, or parse that raw responseText on client via JavaScript or catch the Exception on server and send some response which would be easily to parse.

I would prefer the second approach - catching on server.

RCN
Jun 22, 2012, 11:10 AM
I tried to, but...

Wich one should I use? I tried AjaxResult but didn't work out pretty well.

Thanks in advance,

Daniil
Jun 22, 2012, 11:25 AM
Well, any one that could be easily parsed within the Exception listener.

You could just send a ContentResult with just an error message.

RCN
Jun 22, 2012, 11:46 AM
O.O Niiiiceee...

But tell me, how the Exception listener was fired if I did not threw any exception? (I catched the exception then "return new ContentResult { Content = ex.Message };")

Just curious, the problem is solved, you can close this post

Vladimir
Jun 22, 2012, 12:37 PM
You can return HttpStatusCodeResult with status code and status text



return new HttpStatusCodeResult(500, "Unexpected error is occured");

Status text can be retrieved from response object on the client side


<Exception Handler="alert(response.statusText);" />

Daniil
Jun 22, 2012, 12:43 PM
+1 to Vladimir. It would be best to set up Response.StatusCode to be ensure the response will be considered as a failure one.


But tell me, how the Exception listener was fired if I did not threw any exception? (I catched the exception then "return new ContentResult { Content = ex.Message };")

A JavaScript exception occurs when Loader tries to parse a response

Ext.encode(response);
where the response is just a string with the error message.

Therefore the Exception event is triggered. Certainly, it is not good.

Setting up StatusCode to 500 causes the Loader won't parse the response at all.

RCN
Jun 22, 2012, 5:26 PM
\o/ Thanks a lot you two.

RCN
Jun 22, 2012, 5:38 PM
OK...

To use the

return new HttpStatusCodeResult(500, "Unexpected error is occured");
I replace the return type of my method to ActionResult, to be able to return ContentResult sometimes or HttpStatusCodeResult in case of errors.

When i alert the "response.statusText" it only comes with "Internal server error", despite the fact that i put "Unexpected error is occured" on the constructor.

Vladimir
Jun 22, 2012, 5:51 PM
The ASP.Net Development server (from Visual Studio) eats the status description.
You need to test this with a real IIS server.

Vladimir
Jun 22, 2012, 5:57 PM
Also if you work under IIS 7.0 Integrated mode then it might be able need to set to true the following property
http://msdn.microsoft.com/ru-ru/library/system.web.httpresponse.tryskipiiscustomerrors.asp x

Vladimir
Jun 22, 2012, 6:10 PM
Another approach, if exception is occured then return DisplayField with error message. That display field will be shown inside panel