|
|
@ -1,11 +1,10 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Text; |
|
|
using System.Text; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc.Abstractions; |
|
|
using Microsoft.AspNetCore.Mvc.Abstractions; |
|
|
using Microsoft.AspNetCore.Mvc.Filters; |
|
|
using Microsoft.AspNetCore.Mvc.Filters; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging.Abstractions; |
|
|
using Microsoft.Extensions.Logging.Abstractions; |
|
|
using Microsoft.Extensions.Options; |
|
|
using Microsoft.Extensions.Options; |
|
|
@ -57,14 +56,13 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling |
|
|
//TODO: Trigger an AbpExceptionHandled event or something like that.
|
|
|
//TODO: Trigger an AbpExceptionHandled event or something like that.
|
|
|
|
|
|
|
|
|
context.HttpContext.Response.Headers.Add(AbpHttpConsts.AbpErrorFormat, "true"); |
|
|
context.HttpContext.Response.Headers.Add(AbpHttpConsts.AbpErrorFormat, "true"); |
|
|
context.HttpContext.Response.StatusCode = (int) context.HttpContext.RequestServices |
|
|
context.HttpContext.Response.StatusCode = (int) context |
|
|
.GetRequiredService<IHttpExceptionStatusCodeFinder>() |
|
|
.GetRequiredService<IHttpExceptionStatusCodeFinder>() |
|
|
.GetStatusCode(context.HttpContext, context.Exception); |
|
|
.GetStatusCode(context.HttpContext, context.Exception); |
|
|
|
|
|
|
|
|
var remoteServiceErrorInfo = context.HttpContext.RequestServices |
|
|
var exceptionHandlingOptions = context.GetRequiredService<IOptions<AbpExceptionHandlingOptions>>().Value; |
|
|
.GetRequiredService<IExceptionToErrorInfoConverter>().Convert(context.Exception, |
|
|
var exceptionToErrorInfoConverter = context.GetRequiredService<IExceptionToErrorInfoConverter>(); |
|
|
context.HttpContext.RequestServices.GetRequiredService<IOptions<AbpExceptionHandlingOptions>>() |
|
|
var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, exceptionHandlingOptions.SendExceptionsDetailsToClients); |
|
|
.Value.SendExceptionsDetailsToClients); |
|
|
|
|
|
|
|
|
|
|
|
context.Result = new ObjectResult(new RemoteServiceErrorResponse(remoteServiceErrorInfo)); |
|
|
context.Result = new ObjectResult(new RemoteServiceErrorResponse(remoteServiceErrorInfo)); |
|
|
|
|
|
|
|
|
@ -72,22 +70,15 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling |
|
|
|
|
|
|
|
|
var remoteServiceErrorInfoBuilder = new StringBuilder(); |
|
|
var remoteServiceErrorInfoBuilder = new StringBuilder(); |
|
|
remoteServiceErrorInfoBuilder.AppendLine($"---------- {nameof(RemoteServiceErrorInfo)} ----------"); |
|
|
remoteServiceErrorInfoBuilder.AppendLine($"---------- {nameof(RemoteServiceErrorInfo)} ----------"); |
|
|
remoteServiceErrorInfoBuilder.AppendLine(context.HttpContext.RequestServices |
|
|
remoteServiceErrorInfoBuilder.AppendLine(context.GetRequiredService<IJsonSerializer>().Serialize(remoteServiceErrorInfo, indented: true)); |
|
|
.GetRequiredService<IJsonSerializer>().Serialize(remoteServiceErrorInfo, indented: true)); |
|
|
|
|
|
|
|
|
|
|
|
var logger = context.HttpContext.RequestServices.GetService<ILogger<AbpExceptionFilter>>() ?? |
|
|
var logger = context.GetService<ILogger<AbpExceptionFilter>>(NullLogger<AbpExceptionFilter>.Instance); |
|
|
NullLogger<AbpExceptionFilter>.Instance; |
|
|
|
|
|
|
|
|
|
|
|
logger.LogWithLevel(logLevel, remoteServiceErrorInfoBuilder.ToString()); |
|
|
logger.LogWithLevel(logLevel, remoteServiceErrorInfoBuilder.ToString()); |
|
|
|
|
|
|
|
|
logger.LogException(context.Exception, logLevel); |
|
|
logger.LogException(context.Exception, logLevel); |
|
|
|
|
|
|
|
|
await context.HttpContext |
|
|
await context.GetRequiredService<IExceptionNotifier>().NotifyAsync(new ExceptionNotificationContext(context.Exception)); |
|
|
.RequestServices |
|
|
|
|
|
.GetRequiredService<IExceptionNotifier>() |
|
|
|
|
|
.NotifyAsync( |
|
|
|
|
|
new ExceptionNotificationContext(context.Exception) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
context.Exception = null; //Handled!
|
|
|
context.Exception = null; //Handled!
|
|
|
} |
|
|
} |
|
|
|