【发布时间】:2022-12-11 07:16:38
【问题描述】:
如何在 Web API 的 void 方法中抛出错误(错误请求)
public async Task UpdateRecord([FromBody] UpdateRecord model)
{
try
{
await _recordService.UpdateRecord(model);
}
catch (Exception ex)
{
var message = new NetHttp.HttpResponseMessage(HttpStatusCode.BadRequest);
message.Content = new NetHttp.StringContent(ex.Message);
throw new WebHttp.HttpResponseException(message);
}
}
大摇大摆地显示为 500。但我已经提到 400 - Bad Request
【问题讨论】:
标签: c# asp.net-web-api webapi http-status-code-400 httpresponsemessage