How do I get the error message from an HttpResponse object in WebAPI?
As you figured in your comment, you could either use response.Content.ReadAsAsync<HttpError>()
or you could also use response.TryGetContentValue<HttpError>()
.
In both these cases, the content is checked to see if its of type ObjectContent
and the value is retrieved from it.
You can try the following:
var errorContent = await response.Content.ReadAsAsync<HttpError>();
Assert.That(errorContent.Message,Is.EqualTo("No Permission"));
Try this one. response.Content.ReadAsAsync<HttpError>().Result.Message;