通过 Opw.HttpExceptions.AspNetCore 搞定了。
1)安装 nuget 包 Opw.HttpExceptions.AspNetCore
1 |
<PackageReference Include="Opw.HttpExceptions.AspNetCore" Version="2.3.0" /> |
2)Startup.ConfigureServices 中添加 AddHttpExceptions
1 |
services.AddControllers().AddHttpExceptions(); |
3)Startup.Configure 中添加 UseHttpExceptions
1 |
app.UseHttpExceptions(); |
示例响应输出
1 |
{"type":"error:invalid-cast","title":"InvalidCast","status":500,"detail":"Invalid cast from \u0027System.Int32\u0027 to \u0027Cnblogs.Infrastructure.Primitives.PostConfig\u0027.","instance":"/zzkdocuments"} |
from:https://q.cnblogs.com/q/121590/