using System.Security.Claims; using JNPF.Common.Const; using JNPF.Common.Security; using SqlSugar; namespace Tnb.WarehouseMgr.Entities.Exceptions { /// /// 定时任务自定义异常 /// 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() ?? 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; } } }