0

In my ASP.Net REST controller I do the following:

return BadRequest("A problem happened!"); 

When calling this over HTTP I get the message as follows:

HttpResponseMessage response = await _httpClient.GetAsync(url); if (!response.IsSuccessStatusCode) { var errorMessage = await response.Content.ReadAsStringAsync(); 

But the value of the errorMessage is:

"\"A problem happened!\"" 

When I run through PostMan it doesn't include the quote marks even in the raw output view so I'm not sure if they are being added on for some reason, but I would rather avoid having to manually strip them.

I based my work on this other question where nobody seemed to have this issue: BadRequest custom error message not returned to client?

1 Answer 1

0

It is just a json string, you have to deserialize it

 var errorMessage = "\"A problem happened!\""; // "A problem happened!" var errMsg = JsonConvert.DeserializeObject<string>(errorMessage); // A problem happened! 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.