feat:完成异常处理

This commit is contained in:
陈淳
2023-04-15 14:36:48 +08:00
parent c4f25b7a41
commit 0401e97ed3
6 changed files with 20 additions and 98 deletions

View File

@@ -1,10 +1,12 @@
using System.Runtime.Serialization;
using Furion.FriendlyException;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Yi.Framework.Infrastructure.Enums;
namespace Yi.Framework.Infrastructure.Exceptions
{
public class AuthException : Exception,
public class AuthException : AppFriendlyException,
IHasErrorCode,
IHasErrorDetails,
IHasLogLevel
@@ -27,6 +29,12 @@ namespace Yi.Framework.Infrastructure.Exceptions
Code = (int)code;
Details = details;
LogLevel = logLevel;
base.ErrorCode = code;
base.StatusCode = StatusCodes.Status401Unauthorized;
base.ErrorMessage = $"{message}{(details is not null ? ":" + details : "")}";
base.ValidationException = true;
}
/// <summary>
@@ -38,11 +46,7 @@ namespace Yi.Framework.Infrastructure.Exceptions
}
public AuthException WithData(string name, object value)
{
Data[name] = value;
return this;
}
}
}

View File

@@ -1,10 +1,13 @@
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Furion.FriendlyException;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Yi.Framework.Infrastructure.Enums;
namespace Yi.Framework.Infrastructure.Exceptions
{
public class BusinessException : Exception,
public class BusinessException : AppFriendlyException,
IHasErrorCode,
IHasErrorDetails,
IHasLogLevel
@@ -26,6 +29,10 @@ namespace Yi.Framework.Infrastructure.Exceptions
Code = code;
Details = details;
LogLevel = logLevel;
base.ErrorCode= code;
base.StatusCode = StatusCodes.Status403Forbidden;
base.ErrorMessage = $"{message}{(details is not null? ":"+details:"")}";
base.ValidationException = true;
}
/// <summary>
@@ -37,11 +44,5 @@ namespace Yi.Framework.Infrastructure.Exceptions
}
public BusinessException WithData(string name, object value)
{
Data[name] = value;
return this;
}
}
}