I am sending GET requests from AngularJs and I want to display actual server errors on failure (this is a proof-of-concept, so I can display technical errors to the testers). This works correctly on localhost, but fails for remote requests (when deployed on a server).
Note: irrelevant code is stripped for better readability
Client code
$http(loadReqData).success(function(data, status ) {
if (status !== 200) {
// non OK responses handling ...
return;
}
// ok handling
}).error(function(data, status, headers, config) {
// error handling ...
// here I do not receive expected information (in data variable)
}).finally(function() {
$loading.finish(loaderName);
});
Server-side
This is an MVC controller, not an Web.API one
[Route("GetEnvironmentTableRowCount")]
public JsonResult GetEnvironmentTableRowCount(int environmentId, string tableName, string whereClause)
{
try
{
long? rowCount = TeradataUtilsService.GetRowCount(environmentId, tableName, whereClause);
return Json(new { RowCount = rowCount }, JsonRequestBehavior.AllowGet);
}
catch (Exception exc)
{
Logger.Log(LogLevel.Error, exc, "Failed to get row count");
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Json($"Failed to get row count - {exc.Message}", JsonRequestBehavior.AllowGet);
}
}
When running on localhost and I have an error data
will receive the actual error:
Failed to get row count - ...
When running on a server and I have an error data
will only contain
Bad request
I have allowed custom errors to be shown (web.config):
<system.web>
<customErrors mode="Off" />
</system.web>
Question: why don't I receive the http response content when deployed on a server?