token error 修改

parent 47663fc8
...@@ -25,6 +25,11 @@ public Task OnExceptionAsync(ExceptionContext context) ...@@ -25,6 +25,11 @@ public Task OnExceptionAsync(ExceptionContext context)
_logger.LogWarning($"接口错误警告:{context.Exception.ToString()}"); _logger.LogWarning($"接口错误警告:{context.Exception.ToString()}");
context.Result = new ObjectResult(new ApiResponse(ResponseType.Fail, context.Exception.Message)); context.Result = new ObjectResult(new ApiResponse(ResponseType.Fail, context.Exception.Message));
} }
else if (context.Exception is PerformanceTokenErrorException)
{
_logger.LogWarning($"Token Error:{context.Exception.ToString()}");
context.Result = new ObjectResult(new ApiResponse(ResponseType.TokenError, context.Exception.Message));
}
else else
{ {
_logger.LogError($"接口异常:{context.Exception.ToString()}"); _logger.LogError($"接口异常:{context.Exception.ToString()}");
......
...@@ -23,10 +23,10 @@ public UserIdentity At(ApiRequest request) ...@@ -23,10 +23,10 @@ public UserIdentity At(ApiRequest request)
public UserIdentity At(string token) public UserIdentity At(string token)
{ {
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
throw new PerformanceException("token is not null"); throw new PerformanceTokenErrorException("token is not null");
var user = _memoryCache.Get<UserIdentity>(token); var user = _memoryCache.Get<UserIdentity>(token);
if (user == null) if (user == null)
throw new PerformanceException("当前用户未登录"); throw new PerformanceTokenErrorException("当前用户未登录");
return user; return user;
} }
} }
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;
namespace Performance.DtoModels
{
public class PerformanceTokenErrorException : Exception
{
public PerformanceTokenErrorException()
{
}
public PerformanceTokenErrorException(string message) : base(message)
{
}
public PerformanceTokenErrorException(string message, Exception innerException) : base(message, innerException)
{
}
protected PerformanceTokenErrorException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment