如何显示确切的错误而不是ASP.NET Web API返回UnknowError500

问题描述

当找不到公司及其公司ID时,我想返回404状态代码。但是Web API总是返回;

  "error": {
    "message": "An error has occurred. Please,try it later.","issuedAt": "2020-08-18T08:06:19.4650733Z","code": "UnknownError","statusCode": 500
  }
}

这是我的CustomerProvider代码;

public class CustomerProvider: ICustomerProvider
    {
        public CustomerProvider GetCustomerDetails()
        {
            //.....
            //.....
            
                if (customerDetails == null)
                {
                    var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content = new StringContent(string.Format("No customer with ID = {0}",customerId)),ReasonPhrase = "Company ID Not Found"
                    };
                    throw new HttpResponseException(resp);
                }
            
                return customerDetails;
        }
    }

如何返回404状态代码?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)