如何返回HttpError
(自己的,相当格式化的前端错误消息)然后我使用方便的IHttpActionResult
?
public IHttpActionResult Delete(Guid id)
{
HttpError error = null;
// code omitted
if (error != null) {
// How can I achieve that?
return BadRequest(error);
}
return Ok();
}
答案 0 :(得分:9)
您可以使用ResponseMessageResult:
public IHttpActionResult Error()
{
var error = new HttpError();
return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, error));
}