7

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.

1

1 Answer 1

11

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.