Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

This Web API action returns an HTTP 500 (Internal Server Error) status code:

public IHttpActionResult Post()
{
    return InternalServerError();
}

But this action returns an HTTP 400 (Bad Request) status code:

public IHttpActionResult Post()
{
    return InternalServerError(new Exception());
}

I would expect both actions to return a 500 status code and the second action puts some of the error's details in the response body.

My first thought is that this is a bug but I wanted to get some other input. Is there any good reason why a 400 should be returned in the second action instead of a 500?

UPDATE:

The documentation on this method reads:

Creates an System.Web.Http.Results.ExceptionResult (500 Internal Server Error) with the specified exception.

I'm thinking more and more this is a bug.

share|improve this question
    
There's no issue related to this one, you should open one at aspnetwebstack.codeplex.com/workitem/list/basic – Fals Nov 20 '13 at 18:23
up vote 8 down vote accepted

Right, this was a known issue which was fixed after Web API 2 release...you can use the following workaround to fix this issue..example:

return new ResponseMessageResult(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, invalidOpException));

Following was the issue that was logged before:
https://aspnetwebstack.codeplex.com/workitem/1318

share|improve this answer
    
Cool, thanks for confirming. – jebar8 Nov 20 '13 at 20:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.