I've deployed to a QA server, and the solution is working fine for me, but on some more restrictive networks it behaves differently. The code is as follows:
function RegisterSubmit() {
ShowSpinner();
jQuery.post("@Url.Action("Register", "Home")", jQuery('form#register-form').serialize(),
function (data) { }).done(function (successData) {
// handle success
}).fail(function (xhr, textStatus, errorThrown) {
ShowError('error-message-register', errorThrown);
grecaptcha.reset();
HideSpinner();
});
}
This successfully calls through to the controller, which writes a log to the db with the exception, and I can see this is all working correctly. Where it seems to fall over is how the error is returned to the browser. I'm using the following, which works fine generally:
[AllowAnonymous]
[HttpPost]
public ActionResult Register(RegisterViewModel model, string returnUrl)
{
try
{
model.Validate();
RecaptchaValidator.Validate(TenantId, Request);
// happy path
}
catch (Exception ex)
{
LogException(ex);
return ThrowJsonError(ex);
}
}
It uses the following:
public JsonResult ThrowJsonError(string message)
{
Response.StatusCode = (int) System.Net.HttpStatusCode.BadRequest;
Response.StatusDescription = message;
return Json(new {Message = message}, JsonRequestBehavior.AllowGet);
}
On just this one network, instead of showing the error message, it shows "Bad Request". Any ideas/solutions?
UPDATE As a side note, the success case on this code is working fine, so there is no issue reaching the server. The issue only comes up when we throw an error in the controller and want it to be caught in the view and displayed in the browser.