How to return HTTP 500 from ASP.NET Core RC2 Web Api?

前端 未结 8 2432
忘掉有多难
忘掉有多难 2020-12-04 17:01

Back in RC1, I would do this:

[HttpPost]
public IActionResult Post([FromBody]string something)
{    
    try{
        // ...
    }
    catch(Exception e)
            


        
8条回答
  •  一整个雨季
    2020-12-04 17:59

    return StatusCode((int)HttpStatusCode.InternalServerError, e);
    

    Should be used in non-ASP.NET contexts (see other answers for ASP.NET Core).

    HttpStatusCode is an enumeration in System.Net.

提交回复
热议问题