Handling custom errors with $.ajax method that are passed back from server?
Hi, I want to pass back and handle a custom error message using the $.ajax method. I think I'm close but I'm stuck on parsing the error.
My questions:
-------------
1.) How do I parse the [Exception] section below?. Shows it being returned to client but I was hoping it could be pulled out with a method on the XHR?
2.) Is there a way to set the "textStatus" or "errorThrown" with the custom error and use those on the client? Or are these read-only?
On the server (Using ASP.NET)
//Test to force an a custom server error.
throw new System.Exception("Some error on server");
}
catch (System.Exception ex)
{
Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
Response.StatusDescription = ex.Message;
throw ex;
}
In my $.ajax error handler
error: function (XMLHttpRequest, textStatus, errorThrown) {
//want to handle error and display the custom error here.
}
In the debugger of what I'm getting back.
XMLHttpRequest
<!--
[Exception]: Some error on server <!--It's getting passed back here
...stack trace was here but removed for clarity...
-->"
status: 500
statusText: "Internal Server Error"
textStatus
"error"
errorThrown
"Internal Server Error"