This is a migrated thread and some comments may be shown as answers.

Error Handling for Grid (ASP.Net MVC)

2 Answers 309 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 02 Dec 2012, 12:26 AM
After a lot of searching for a clean way to convey errors to the user from a grid database operation I found the following suggestion:
return new HttpStatusCodeResult(int, string)
This worked really well and allowed me to trap Exceptions and then turn them into more user friendly responses. In one case I simply passed on the Exception.Message as the string. But when I tested it by forcing a SQL Error, it didn't work. After hours of experimenting, I eventually found that if the string contained CRLF sequences this meant it was not handled properly by the OnError script on the browser. I fixed this by doing something similar to:
catch (Exception e)
{
    return new HttpStatusCodeResult(550, e.Message.Replace("\r\n", "<br />"));
}
In other words I replaced all the CRLF sequences by br html elements.This works, but it seems to me this is very fragile. So my questions are:
  1. Is the error with the ASP.Net code or with the Keno UI code?
  2. If I have missed some fine print somewhere what generalized steps can I take to ensure this works in all cases?
Many thanks

2 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 05 Dec 2012, 08:34 AM
Hi Martin,

I'm afraid that it is not clear what is your exact scenario and implementation nor what might be the cause for the issue. Therefore, could you please provide a small run-able sample which demonstrates the issue.

All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Martin
Top achievements
Rank 1
answered on 05 Dec 2012, 11:16 PM
I have spent the day trying to create a project to demonstrate the problem. Finally I figured out that the problem is Visual Studio. So I post this as a cautionary tale for other testers.
The code below:
return new HttpStatusCodeResult(550, "Some error")
cannot be tested in Visual Studio, or at least definitely not in VS2012 because the VS development webserver destroys the value of statusText which should contain the "Some error" string. 

When I deployed this app to a real IIS webserver it worked just fine and the error message is displayed exactly as expected.

So after 2 days of wasted effort, I can now continue with the code that was working correctly in the first place.I had just assumed that the response was damaged by something I was doing wrong in my Grid error processing.

Sorry to have wasted your time.
Tags
Grid
Asked by
Martin
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Martin
Top achievements
Rank 1
Share this question
or