My API currently returns the bank values in JSON.
If no value is found, I return a HttpResponseMessage
with error code 404.
However, when testing the request, only the message contained in Content
is displayed.
I would like to return all the filled values ( Content
, StatusCode
and ReasonPhrase
) in the JSON style (key-value).
Is this possible?
[HttpGet]
[Route("user/")]
public List<user> Get()
{
new UserController();
IQueryable<user> users = from itens in db.user select itens;
if (!users.Any())
{
HttpResponseMessage error = new HttpResponseMessage(HttpStatusCode.NotFound)
{
Content = new StringContent(string.Format("Nenhum usuário encontrado")),
StatusCode = HttpStatusCode.NotFound,
ReasonPhrase = "User Not Found"
};
throw new HttpResponseException(error);
}
return users.ToList();
}
}