mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-03-24 17:57:21 +08:00
# 2022-04-10
### 1.4.4开源社区版: 无 ### 0.3.5 专业版: 【新增】增加用户操作日志,可记录接口也可记录后台,同时支持本地存储或数据库存储。支持配置文件开启。 【新增】数据库增加用户操作日志表。 【优化】优化反射获取所有Controller 和Action的全局方法,增加缓存设置。 【优化】优化记录IP请求数据的中间件。 【修复】修复ios下用户充值余额的功能不显示的情况。 【修复】修复我的余额面板列表中右侧三角无反应的问题。 【修复】修复代理中心下线人数和订单数量统计错误的问题。#I51OUC
This commit is contained in:
@@ -13,69 +13,63 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
|
||||
namespace CoreCms.Net.Middlewares
|
||||
namespace CoreCms.Net.Middlewares;
|
||||
|
||||
/// <summary>
|
||||
/// 异常错误统一返回记录
|
||||
/// </summary>
|
||||
public class ExceptionHandlerMiddForClent
|
||||
{
|
||||
/// <summary>
|
||||
/// 异常错误统一返回记录
|
||||
/// </summary>
|
||||
public class ExceptionHandlerMiddForClent
|
||||
private readonly RequestDelegate _next;
|
||||
|
||||
|
||||
public ExceptionHandlerMiddForClent(RequestDelegate next)
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
_next = next;
|
||||
}
|
||||
|
||||
|
||||
public ExceptionHandlerMiddForClent(RequestDelegate next)
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
_next = next;
|
||||
await _next(context);
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
catch (Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _next(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await HandleExceptionAsync(context, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleExceptionAsync(HttpContext context, Exception ex)
|
||||
{
|
||||
if (ex == null) return;
|
||||
|
||||
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.ApiRequest, "全局捕获异常", "全局捕获异常", new Exception("全局捕获异常", ex));
|
||||
|
||||
await WriteExceptionAsync(context, ex).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static async Task WriteExceptionAsync(HttpContext context, Exception e)
|
||||
{
|
||||
if (e is UnauthorizedAccessException)
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||
else if (e is Exception)
|
||||
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
|
||||
context.Response.ContentType = "application/json";
|
||||
var jm = new WebApiCallBack();
|
||||
jm.status = false;
|
||||
jm.code = 500;
|
||||
jm.data = e;
|
||||
jm.msg = "全局数据异常";
|
||||
await context.Response.WriteAsync(JsonConvert.SerializeObject(jm)).ConfigureAwait(false);
|
||||
await HandleExceptionAsync(context, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleExceptionAsync(HttpContext context, Exception ex)
|
||||
{
|
||||
if (ex == null) return;
|
||||
|
||||
NLogUtil.WriteAll(LogLevel.Error, LogType.ApiRequest, "全局捕获异常", "全局捕获异常", new Exception("全局捕获异常", ex));
|
||||
|
||||
await WriteExceptionAsync(context, ex).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static async Task WriteExceptionAsync(HttpContext context, Exception e)
|
||||
{
|
||||
if (e is UnauthorizedAccessException)
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||
else if (e != null)
|
||||
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
|
||||
context.Response.ContentType = "application/json";
|
||||
var jm = new WebApiCallBack();
|
||||
jm.status = false;
|
||||
jm.code = 500;
|
||||
jm.data = e;
|
||||
jm.msg = "全局数据异常";
|
||||
await context.Response.WriteAsync(JsonConvert.SerializeObject(jm)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user