My WebAPI method returns an error response:
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Something bad happened");
At my client end (MVC project) I want to display an error message, but could not get the message “Something bad happened” to display:
var response = await client.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
ViewBag.Error= response.ReasonPhrase;
}
Besides ReasonPhrase, I have tried response.ToString(), response.Content.ToString()and response.Content.ReadAsStringAsync(). None of them received me a message. Why can Postman display a message?
Any ideas on how I can access the message line?
source
share