i see that i get a big html text when i return a HttpException() from an ajax call.
if i do something like this in my controller:
if (errors.Count > 0)
{
throw new HttpException(404, "This is my custom error msg");
}
i want a nice simple way to parse out that Error Message on the javascript side. Right now when i look at the callback on the client side with something like this
function decodeErrorMessage(jqXHR, textStatus, errorThrown) {
i see that jqxHR = “3”, textStatus = a very long html doc (with a a call stack and error message and errorThrown is “error”
what is the best way to simply pass back and show an error from an http exception?
Instead of throwing the exception in the controller, catch it and set the response code for the AJAX response:
View logic setup with JQuery:
Then in your Controller code you catch the exception instead of throwing it: