|
|
@ -7,9 +7,11 @@ using Microsoft.AspNetCore.Cors; |
|
|
|
using Microsoft.AspNetCore.DataProtection; |
|
|
|
using Microsoft.AspNetCore.Http.Features; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.AspNetCore.Mvc.Filters; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.OpenApi.Models; |
|
|
|
using StackExchange.Redis; |
|
|
|
using Swashbuckle.AspNetCore.SwaggerUI; |
|
|
@ -20,6 +22,7 @@ using System.Text.Json; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.AspNetCore.ExceptionHandling; |
|
|
|
using Volo.Abp.AspNetCore.Mvc; |
|
|
|
using Volo.Abp.AspNetCore.Mvc.ExceptionHandling; |
|
|
|
using Volo.Abp.AspNetCore.Serilog; |
|
|
|
using Volo.Abp.AuditLogging.EntityFrameworkCore; |
|
|
|
using Volo.Abp.Autofac; |
|
|
@ -258,6 +261,17 @@ namespace Win.Sfs.SettleAccount |
|
|
|
{ |
|
|
|
//将错误明细发送给客户端
|
|
|
|
Configure<AbpExceptionHandlingOptions>(options => { options.SendExceptionsDetailsToClients = true; }); |
|
|
|
|
|
|
|
Configure<MvcOptions>(options => |
|
|
|
{ |
|
|
|
var index = options.Filters.ToList().FindIndex(filter => filter is ServiceFilterAttribute attr && attr.ServiceType.Equals(typeof(AbpExceptionFilter))); |
|
|
|
if (index > -1) |
|
|
|
{ |
|
|
|
options.Filters.RemoveAt(index); |
|
|
|
} |
|
|
|
options.Filters.Add(typeof(CustomExceptionFilter)); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureMultiTenancy() |
|
|
@ -476,4 +490,21 @@ namespace Win.Sfs.SettleAccount |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class CustomExceptionFilter : IExceptionFilter |
|
|
|
{ |
|
|
|
private readonly ILogger<CustomExceptionFilter> logger; |
|
|
|
|
|
|
|
public CustomExceptionFilter(ILogger<CustomExceptionFilter> logger) |
|
|
|
{ |
|
|
|
this.logger = logger; |
|
|
|
} |
|
|
|
public void OnException(ExceptionContext context) |
|
|
|
{ |
|
|
|
logger.LogError(new EventId(context.Exception.HResult), context.Exception, context.Exception.Message); |
|
|
|
var message = context.Exception.InnerException?.InnerException?.Message ?? context.Exception.Message; |
|
|
|
context.Result = new JsonResult(new { code = 400, message }); |
|
|
|
context.ExceptionHandled = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|