Files
Yi.Admin/Yi.Furion.Net6/Yi.Framework.Infrastructure/Exceptions/AuthException.cs

53 lines
1.3 KiB
C#
Raw Normal View History

2023-04-13 21:12:06 +08:00
using System.Runtime.Serialization;
2023-04-15 14:36:48 +08:00
using Furion.FriendlyException;
using Microsoft.AspNetCore.Http;
2023-04-13 21:12:06 +08:00
using Microsoft.Extensions.Logging;
using Yi.Framework.Infrastructure.Enums;
namespace Yi.Framework.Infrastructure.Exceptions
{
2023-04-15 14:36:48 +08:00
public class AuthException : AppFriendlyException,
2023-04-13 21:12:06 +08:00
IHasErrorCode,
IHasErrorDetails,
IHasLogLevel
{
public int Code { get; set; }
public string? Details { get; set; }
public LogLevel LogLevel { get; set; }
public AuthException(
string? message = null,
ResultCodeEnum code = ResultCodeEnum.NoPermission,
string? details = null,
Exception? innerException = null,
LogLevel logLevel = LogLevel.Warning)
: base(message, innerException)
{
Code = (int)code;
Details = details;
LogLevel = logLevel;
2023-04-15 14:36:48 +08:00
base.ErrorCode = code;
base.StatusCode = StatusCodes.Status401Unauthorized;
base.ErrorMessage = $"{message}{(details is not null ? ":" + details : "")}";
base.ValidationException = true;
2023-04-13 21:12:06 +08:00
}
/// <summary>
/// 序列化参数的构造函数
/// </summary>
public AuthException(SerializationInfo serializationInfo, StreamingContext context)
: base(serializationInfo, context)
{
}
2023-04-15 14:36:48 +08:00
2023-04-13 21:12:06 +08:00
}
}