How to throw error (Bad Request) in void method in Web API
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);
}
}
In swagger, its showing as 500. But I have mentioned 400 - Bad Request