57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
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, ErrorInfo exceptionInfo)
|
|
{
|
|
TimedTaskException ex = new(exception.Message, exceptionInfo.RequestURL, exceptionInfo.RequestMethod, exceptionInfo.userIdentity, exception);
|
|
return ex;
|
|
}
|
|
}
|
|
|
|
public class ErrorInfo
|
|
{
|
|
public string RequestURL { get; set; }
|
|
public string RequestMethod { get; set; }
|
|
public ClaimsPrincipal userIdentity { get; set; }
|
|
|
|
}
|
|
}
|