I would like to return an exception message to the AngularJS user interface. As a back-end, I use the ASP.NET Core Web Api controller:
[Route("api/cars/{carNumber}")]
public string Get(string carNumber)
{
var jsonHttpResponse = _carInfoProvider.GetAllCarsByNumber(carNumber);
if (jsonHttpResponse.HasError)
{
var message = new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
Content = new StringContent(jsonHttpResponse.ErrorMessage)
};
throw new HttpResponseException(message);
}
return jsonHttpResponse.Content;
}
But on the Angular side, the failure failure sees only the status and statusText "Internal server error":

How to pass error message on Angular $ http rejection of Core Web Api?
source
share