Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpError and IHttpActionResult

How can I return HttpError (own, pretty formatted, error message for front-end) then I use handy IHttpActionResult?

public IHttpActionResult Delete(Guid id)
{
    HttpError error = null;

    // code omitted

    if (error != null) {
        // How can I achieve that?
        return BadRequest(error);
    }

    return Ok();
}
like image 610
kseen Avatar asked May 23 '14 03:05

kseen


1 Answers

You can use ResponseMessageResult:

public IHttpActionResult Error()
{
    var error = new HttpError();
    return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, error));
}
like image 195
Konstantin Smolyakov Avatar answered Oct 25 '22 09:10

Konstantin Smolyakov