Web API 2 - Using ReasonPhrase in exception handling

1
var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
{
    ReasonPhrase = "Nenhum produto encontrado"
};

throw new HttpResponseException(resp);

This code should return

  

404 No products found

But for some reason it is not working. Any idea? I'm using Visual Studio 2013 and IIS Express.

Print example (ignore the URL and use of HEAD, just to illustrate)

    
asked by anonymous 13.03.2014 / 15:42

1 answer

1

Well, apparently the tip given by the Gypsy Morrison Mendez is correct, I did a little test using the JS below:

$.ajax({
    type: "GET",
    url: 'api/teste/?id=1',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (result) {
        alert(result.CustomerID + " - " + result.CompanyName);
    },
    error: function (err, type, httpStatus) {
        alert(err.status + " - " + err.statusText + " - " + httpStatus);
    }
});

And then it worked, it showed ReasonPhrase and the content of the answer. I'm going to use Fiddler to avoid this kind of thing!

    
13.03.2014 / 18:44