Files
Yi.Framework/Yi.Doc.Md/02.框架功能模块/14.异常处理.md
2023-12-15 23:44:35 +08:00

48 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 简介
当程序出现异常之后,框架需要记录,同时反馈前端对应的信息
它通过`全局错误中间件`实现
错误后,将统一返回以下模型格式:
``` cs
public class RemoteServiceErrorInfo
{
public string? Code { get; set; }
/// <summary>
/// message.
/// </summary>
public string? Message { get; set; }
/// <summary>
/// details.
/// </summary>
public string? Details { get; set; }
/// <summary>
/// data.
/// </summary>
public object? Data { get; set; }
}
```
框架内部错误分为三大类:
#### 系统内部错误
> httpCode500
系统不能处理、或未发现的错误,需要即使进行修复
#### 业务友好错误
> httpCode:403
跟业务相关,业务请求不合理,例如:登录失败、数据重复
#### 授权错误
> httpCode:401
跟权限相关,代表当前用户权限不足
## 使用
你可以在程序任何地方进行抛出错误
``` cs
throw new Exception("系统错误");//状态码500
throw new UserFriendlyException("业务错误");//状态码403
throw new NotImplementedException("未实现");//状态码501
throw new UserFriendlyException("花里胡哨错误","401");//状态码401
```
Abp内部将自动抓取并返回给前端