Files
tnb.server/WarehouseMgr/Tnb.WarehouseMgr.Entities/Exceptions/TimedTaskException.cs
2023-11-06 19:35:59 +08:00

52 lines
1.8 KiB
C#

using System.Security.Claims;
using JNPF.Common.Const;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.WarehouseMgr.Entities.Exceptions
{
/// <summary>
/// 定时任务自定义异常
/// </summary>
public class TimedTaskException : Exception
{
public string Method { get; set; }
public string UserId { get; set; }
public string UserName { get; set; }
public string RequestURL { get; set; }
public string RequestMethod { get; set; }
public ClaimsPrincipal UserIdentity { get; set; }
public ConnectionConfigOptions? options { get; set; }
public TimedTaskException(string message,
string requestUrl,
string requestMethod,
ClaimsPrincipal userIdentity,
Exception innerException) : base(message, innerException)
{
this.UserId = userIdentity.FindFirst(ClaimConst.CLAINMUSERID)?.Value ?? string.Empty;
this.UserName = userIdentity.FindFirst(ClaimConst.CLAINMREALNAME)?.Value ?? string.Empty;
this.options = userIdentity.FindFirst(ClaimConst.CONNECTIONCONFIG)?.ToObject<ConnectionConfigOptions>() ?? null;
this.RequestURL = requestUrl;
this.RequestMethod = requestMethod;
}
}
public static class TimedTaskExceptionExtensions
{
public static TimedTaskException ToTimedTaskException(this Exception exception, TimedTaskErrorInfo exceptionInfo)
{
TimedTaskException ex = new(exception.Message, exceptionInfo.RequestURL, exceptionInfo.RequestMethod, exceptionInfo.userIdentity, exception);
return ex;
}
}
public class TimedTaskErrorInfo
{
public string RequestURL { get; set; }
public string RequestMethod { get; set; }
public ClaimsPrincipal userIdentity { get; set; }
}
}