You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using Common.Utilities;
|
|
|
|
|
using djy.Model;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace djy_AfrApi.Milldlewares
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 处理特殊情况下的响应格式(401、403)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class UnifyResultMiddleware
|
|
|
|
|
{
|
|
|
|
|
private readonly RequestDelegate _next;
|
|
|
|
|
public UnifyResultMiddleware(RequestDelegate next)
|
|
|
|
|
{
|
|
|
|
|
_next = next;
|
|
|
|
|
}
|
|
|
|
|
public async Task InvokeAsync(HttpContext context)
|
|
|
|
|
{
|
|
|
|
|
await _next(context);
|
|
|
|
|
|
|
|
|
|
if (context.Response.StatusCode == 401 || context.Response.StatusCode == 403)
|
|
|
|
|
{
|
|
|
|
|
context.Response.ContentType = "application/json";
|
|
|
|
|
|
|
|
|
|
await context.Response
|
|
|
|
|
.WriteAsync(JsonConvert.SerializeObject(
|
|
|
|
|
new Response()
|
|
|
|
|
{
|
|
|
|
|
Code = context.Response.StatusCode,
|
|
|
|
|
Message = "授权验证失败或已过期,请重新登录!"
|
|
|
|
|
}))
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|