I'm trying to have a C# exception caught clientside, currently we have a section where a logged in user gets a delete link, if clicked we do a check to make sure the user is still logged in before deleting. if not logged in anymore, the code throws and exception.
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public static void DeleteComment(Guid commentId)
{
try
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
UserEntity currentUser = ((UserEntity)Membership.GetUser());
.. do work
}
else
{
throw new HttpException(401, "401");
}
}
catch (Exception)
{
throw;
}
}
this error goes to the javascript code, which then is checked:
if (result.responseJSON.Message == "401") {
this works fine in our local environment, the Message field contains 401 and the result.responseJSON.ExceptionType contains "System.Web.HttpException", but when trying in our staging environment we get a 500 error code instead and the ExceptionType is ""
I've tried remote dugging and I see the exception occurring when not logged in, it's thrown but when it hits the client side code it's always 500.