refactor: 重构异常处理
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Core.Enums;
|
||||
using Yi.Framework.Core.Exceptions;
|
||||
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
@@ -37,7 +38,7 @@ namespace Microsoft.AspNetCore.Builder
|
||||
catch (BusinessException businessEx)
|
||||
{
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
//context.Response.StatusCode = businessEx.Code.GetHashCode();
|
||||
context.Response.StatusCode = (int)ResultCodeEnum.Denied;
|
||||
|
||||
var result = new ExceptionModle
|
||||
{
|
||||
@@ -59,7 +60,7 @@ namespace Microsoft.AspNetCore.Builder
|
||||
//系统错误,记录日志
|
||||
_logger.LogError(ex, $"授权失败:{ex.Message}");
|
||||
//await _errorHandle.Invoer(context, ex);
|
||||
context.Response.StatusCode = (int)ex.Code;
|
||||
context.Response.StatusCode = (int)ResultCodeEnum.NoPermission;
|
||||
//系统错误,需要记录
|
||||
var result = new ExceptionModle
|
||||
{
|
||||
@@ -80,7 +81,7 @@ namespace Microsoft.AspNetCore.Builder
|
||||
//系统错误,记录日志
|
||||
_logger.LogError(ex, $"系统错误:{ex.Message}");
|
||||
//await _errorHandle.Invoer(context, ex);
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusCode = (int)ResultCodeEnum.NotSuccess;
|
||||
//系统错误,需要记录
|
||||
var result = new ExceptionModle
|
||||
{
|
||||
|
||||
@@ -21,6 +21,11 @@ namespace Yi.Framework.Core.Enums
|
||||
/// <summary>
|
||||
/// 无权限
|
||||
/// </summary>
|
||||
NoPermission = 401
|
||||
NoPermission = 401,
|
||||
|
||||
/// <summary>
|
||||
/// 被拒绝
|
||||
/// </summary>
|
||||
Denied = 403
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Yi.Framework.Core.Exceptions
|
||||
public LogLevel LogLevel { get; set; }
|
||||
|
||||
public BusinessException(
|
||||
int code = (int)ResultCodeEnum.NotSuccess,
|
||||
int code = (int)ResultCodeEnum.Denied,
|
||||
string? message = null,
|
||||
string? details = null,
|
||||
Exception? innerException = null,
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Yi.Framework.Core.Exceptions
|
||||
{
|
||||
public UserFriendlyException(
|
||||
string message,
|
||||
int code = (int)ResultCodeEnum.NotSuccess,
|
||||
int code = (int)ResultCodeEnum.Denied,
|
||||
string? details = null,
|
||||
Exception? innerException = null,
|
||||
LogLevel logLevel = LogLevel.Warning)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user