官网文档地址:https://docs.abp.io/zh-Hans/abp/latest/Exception-Handling
官网写的太过于啰嗦
实际用的时候只需在host中的Startup文件中的ConfigureServices中添加以下代码
然后在代码中使用 BusinessException不适用 直接抛给前端,抛给前端不会把信息扔出 BusinessException适用于应用层
如果返回前端异常 使用 UserFriendlyException("错误内容");
throw new UserFriendlyException("异常信息");
结果
{
"error": {
"code": "",
"message": "异常信息",
"details": null,
"data": {},
"validationErrors": null
}
}
throw new BusinessException(code: "", message: e.Message+"===="+e.InnerException, details: "");
结果
{
"error": {
"code": "",
"message": "An internal error occurred during your request!",
"details": null,
"data": {},
"validationErrors": null
}
}