摘要:
当一个web api抛出一个异常后此异常会被转化成一个HTTP响应错误代码为500的服务错误但是如果你不想让客户端看到500的错误码你也可以自定义错误码如下代码当用户输入的ID没有与之相关的数据则返回了错误码为404的错误(页面未找到)public Product GetProduct(int id) { Product item = repository.Get(id); if (item == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.... 阅读全文