From 3ce989eb05c1b018c312bd2fde63674f9be95c42 Mon Sep 17 00:00:00 2001 From: Berkan Sasmaz Date: Thu, 11 Nov 2021 11:28:08 +0300 Subject: [PATCH] Rename EnableStackTrace to SendStackTraceToClients --- docs/en/Exception-Handling.md | 4 ++-- .../ExceptionHandling/UserExceptionInformer.cs | 2 +- .../Controllers/ErrorController.cs | 2 +- .../ExceptionHandling/AbpExceptionFilter.cs | 2 +- .../AbpExceptionPageFilter.cs | 2 +- .../AbpExceptionHandlingMiddleware.cs | 2 +- .../AbpExceptionHandlingOptions.cs | 17 ++--------------- .../DefaultExceptionToErrorInfoConverter.cs | 18 +++++++++--------- 8 files changed, 18 insertions(+), 31 deletions(-) diff --git a/docs/en/Exception-Handling.md b/docs/en/Exception-Handling.md index 2d62393ea3..d12e9a62b6 100644 --- a/docs/en/Exception-Handling.md +++ b/docs/en/Exception-Handling.md @@ -329,12 +329,12 @@ You can also throw these type of exceptions in your code (although it's rarely n Configure(options => { options.SendExceptionsDetailsToClients = true; - options.EnableStackTrace = false; + options.SendStackTraceToClients = false; }); ```` Here, a list of the options you can configure: * `SendExceptionsDetailsToClients` (default: `false`): You can enable or disable sending exception details to the client. -* `EnableStackTrace` (default: `false`): You can enable or disable sending the `StackTrace` of exception to the client. When you set `EnableStackTrace` to true, it is set to `true` even if `SendExceptionsDetailsToClients` is `false` because it contains the exception details. +* `SendStackTraceToClients` (default: `true`): You can enable or disable sending the stack trace of exception to the client. If you want to send the stack trace to the client, you must set both `SendStackTraceToClients` and `SendExceptionsDetailsToClients` options to `true` otherwise, the stack trace will not be sent to the client. diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ExceptionHandling/UserExceptionInformer.cs b/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ExceptionHandling/UserExceptionInformer.cs index a98628e7dd..ecbeb16e81 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ExceptionHandling/UserExceptionInformer.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ExceptionHandling/UserExceptionInformer.cs @@ -66,7 +66,7 @@ namespace Volo.Abp.AspNetCore.Components.Web.ExceptionHandling return ExceptionToErrorInfoConverter.Convert(context.Exception, options => { options.SendExceptionsDetailsToClients = Options.SendExceptionsDetailsToClients; - options.EnableStackTrace = Options.EnableStackTrace; + options.SendStackTraceToClients = Options.SendStackTraceToClients; }); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Controllers/ErrorController.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Controllers/ErrorController.cs index 365b5479f2..16b6f6e325 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Controllers/ErrorController.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Controllers/ErrorController.cs @@ -50,7 +50,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Controllers var errorInfo = _errorInfoConverter.Convert(exception, options => { options.SendExceptionsDetailsToClients = _exceptionHandlingOptions.SendExceptionsDetailsToClients; - options.EnableStackTrace = _exceptionHandlingOptions.EnableStackTrace; + options.SendStackTraceToClients = _exceptionHandlingOptions.SendStackTraceToClients; }); if (httpStatusCode == 0) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs index 0b43ead885..89f3694c4f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs @@ -62,7 +62,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, options => { options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients; - options.EnableStackTrace = exceptionHandlingOptions.EnableStackTrace; + options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients; }); var logLevel = context.Exception.GetLogLevel(); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs index b0925facc4..51bfd41f84 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs @@ -74,7 +74,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, options => { options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients; - options.EnableStackTrace = exceptionHandlingOptions.EnableStackTrace; + options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients; }); var logLevel = context.Exception.GetLogLevel(); diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingMiddleware.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingMiddleware.cs index 491501720a..02a1e8f888 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingMiddleware.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingMiddleware.cs @@ -89,7 +89,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling errorInfoConverter.Convert(exception, options => { options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients; - options.EnableStackTrace = exceptionHandlingOptions.EnableStackTrace; + options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients; }) ) ) diff --git a/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingOptions.cs b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingOptions.cs index 8a66da1a86..df2073e9d8 100644 --- a/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingOptions.cs +++ b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingOptions.cs @@ -2,21 +2,8 @@ { public class AbpExceptionHandlingOptions { - public bool SendExceptionsDetailsToClients { get; set; } - - private bool _enableStackTrace; + public bool SendExceptionsDetailsToClients { get; set; } = false; - public bool EnableStackTrace - { - get => _enableStackTrace; - set - { - _enableStackTrace = value; - if (_enableStackTrace) - { - SendExceptionsDetailsToClients = true; - } - } - } + public bool SendStackTraceToClients { get; set; } = true; } } diff --git a/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs index 24251731a5..2c5feb8467 100644 --- a/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs +++ b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs @@ -42,7 +42,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling { var exceptionHandlingOptions = CreateDefaultOptions(); exceptionHandlingOptions.SendExceptionsDetailsToClients = includeSensitiveDetails; - exceptionHandlingOptions.EnableStackTrace = includeSensitiveDetails; + exceptionHandlingOptions.SendStackTraceToClients = includeSensitiveDetails; var errorInfo = CreateErrorInfoWithoutCode(exception, exceptionHandlingOptions); @@ -73,7 +73,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling { if (options.SendExceptionsDetailsToClients) { - return CreateDetailedErrorInfoFromException(exception, options.EnableStackTrace); + return CreateDetailedErrorInfoFromException(exception, options.SendStackTraceToClients); } exception = TryToGetActualException(exception); @@ -213,11 +213,11 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling return exception; } - protected virtual RemoteServiceErrorInfo CreateDetailedErrorInfoFromException(Exception exception, bool enableStackTrace) + protected virtual RemoteServiceErrorInfo CreateDetailedErrorInfoFromException(Exception exception, bool sendStackTraceToClients) { var detailBuilder = new StringBuilder(); - AddExceptionToDetails(exception, detailBuilder, enableStackTrace); + AddExceptionToDetails(exception, detailBuilder, sendStackTraceToClients); var errorInfo = new RemoteServiceErrorInfo(exception.Message, detailBuilder.ToString()); @@ -229,7 +229,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling return errorInfo; } - protected virtual void AddExceptionToDetails(Exception exception, StringBuilder detailBuilder, bool enableStackTrace) + protected virtual void AddExceptionToDetails(Exception exception, StringBuilder detailBuilder, bool sendStackTraceToClients) { //Exception Message detailBuilder.AppendLine(exception.GetType().Name + ": " + exception.Message); @@ -256,7 +256,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling } //Exception StackTrace - if (enableStackTrace && !string.IsNullOrEmpty(exception.StackTrace)) + if (sendStackTraceToClients && !string.IsNullOrEmpty(exception.StackTrace)) { detailBuilder.AppendLine("STACK TRACE: " + exception.StackTrace); } @@ -264,7 +264,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling //Inner exception if (exception.InnerException != null) { - AddExceptionToDetails(exception.InnerException, detailBuilder, enableStackTrace); + AddExceptionToDetails(exception.InnerException, detailBuilder, sendStackTraceToClients); } //Inner exceptions for AggregateException @@ -278,7 +278,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling foreach (var innerException in aggException.InnerExceptions) { - AddExceptionToDetails(innerException, detailBuilder, enableStackTrace); + AddExceptionToDetails(innerException, detailBuilder, sendStackTraceToClients); } } } @@ -321,7 +321,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling return new AbpExceptionHandlingOptions { SendExceptionsDetailsToClients = false, - EnableStackTrace = false + SendStackTraceToClients = true }; } }