Rename EnableStackTrace to SendStackTraceToClients

pull/10594/head
Berkan Sasmaz 4 years ago
parent f75747e7e7
commit 3ce989eb05

@ -329,12 +329,12 @@ You can also throw these type of exceptions in your code (although it's rarely n
Configure<AbpExceptionHandlingOptions>(options => Configure<AbpExceptionHandlingOptions>(options =>
{ {
options.SendExceptionsDetailsToClients = true; options.SendExceptionsDetailsToClients = true;
options.EnableStackTrace = false; options.SendStackTraceToClients = false;
}); });
```` ````
Here, a list of the options you can configure: Here, a list of the options you can configure:
* `SendExceptionsDetailsToClients` (default: `false`): You can enable or disable sending exception details to the client. * `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.

@ -66,7 +66,7 @@ namespace Volo.Abp.AspNetCore.Components.Web.ExceptionHandling
return ExceptionToErrorInfoConverter.Convert(context.Exception, options => return ExceptionToErrorInfoConverter.Convert(context.Exception, options =>
{ {
options.SendExceptionsDetailsToClients = Options.SendExceptionsDetailsToClients; options.SendExceptionsDetailsToClients = Options.SendExceptionsDetailsToClients;
options.EnableStackTrace = Options.EnableStackTrace; options.SendStackTraceToClients = Options.SendStackTraceToClients;
}); });
} }
} }

@ -50,7 +50,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Controllers
var errorInfo = _errorInfoConverter.Convert(exception, options => var errorInfo = _errorInfoConverter.Convert(exception, options =>
{ {
options.SendExceptionsDetailsToClients = _exceptionHandlingOptions.SendExceptionsDetailsToClients; options.SendExceptionsDetailsToClients = _exceptionHandlingOptions.SendExceptionsDetailsToClients;
options.EnableStackTrace = _exceptionHandlingOptions.EnableStackTrace; options.SendStackTraceToClients = _exceptionHandlingOptions.SendStackTraceToClients;
}); });
if (httpStatusCode == 0) if (httpStatusCode == 0)

@ -62,7 +62,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling
var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, options => var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, options =>
{ {
options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients; options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients;
options.EnableStackTrace = exceptionHandlingOptions.EnableStackTrace; options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients;
}); });
var logLevel = context.Exception.GetLogLevel(); var logLevel = context.Exception.GetLogLevel();

@ -74,7 +74,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling
var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, options => var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, options =>
{ {
options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients; options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients;
options.EnableStackTrace = exceptionHandlingOptions.EnableStackTrace; options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients;
}); });
var logLevel = context.Exception.GetLogLevel(); var logLevel = context.Exception.GetLogLevel();

@ -89,7 +89,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
errorInfoConverter.Convert(exception, options => errorInfoConverter.Convert(exception, options =>
{ {
options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients; options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients;
options.EnableStackTrace = exceptionHandlingOptions.EnableStackTrace; options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients;
}) })
) )
) )

@ -2,21 +2,8 @@
{ {
public class AbpExceptionHandlingOptions public class AbpExceptionHandlingOptions
{ {
public bool SendExceptionsDetailsToClients { get; set; } public bool SendExceptionsDetailsToClients { get; set; } = false;
private bool _enableStackTrace;
public bool EnableStackTrace public bool SendStackTraceToClients { get; set; } = true;
{
get => _enableStackTrace;
set
{
_enableStackTrace = value;
if (_enableStackTrace)
{
SendExceptionsDetailsToClients = true;
}
}
}
} }
} }

@ -42,7 +42,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
{ {
var exceptionHandlingOptions = CreateDefaultOptions(); var exceptionHandlingOptions = CreateDefaultOptions();
exceptionHandlingOptions.SendExceptionsDetailsToClients = includeSensitiveDetails; exceptionHandlingOptions.SendExceptionsDetailsToClients = includeSensitiveDetails;
exceptionHandlingOptions.EnableStackTrace = includeSensitiveDetails; exceptionHandlingOptions.SendStackTraceToClients = includeSensitiveDetails;
var errorInfo = CreateErrorInfoWithoutCode(exception, exceptionHandlingOptions); var errorInfo = CreateErrorInfoWithoutCode(exception, exceptionHandlingOptions);
@ -73,7 +73,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
{ {
if (options.SendExceptionsDetailsToClients) if (options.SendExceptionsDetailsToClients)
{ {
return CreateDetailedErrorInfoFromException(exception, options.EnableStackTrace); return CreateDetailedErrorInfoFromException(exception, options.SendStackTraceToClients);
} }
exception = TryToGetActualException(exception); exception = TryToGetActualException(exception);
@ -213,11 +213,11 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
return exception; return exception;
} }
protected virtual RemoteServiceErrorInfo CreateDetailedErrorInfoFromException(Exception exception, bool enableStackTrace) protected virtual RemoteServiceErrorInfo CreateDetailedErrorInfoFromException(Exception exception, bool sendStackTraceToClients)
{ {
var detailBuilder = new StringBuilder(); var detailBuilder = new StringBuilder();
AddExceptionToDetails(exception, detailBuilder, enableStackTrace); AddExceptionToDetails(exception, detailBuilder, sendStackTraceToClients);
var errorInfo = new RemoteServiceErrorInfo(exception.Message, detailBuilder.ToString()); var errorInfo = new RemoteServiceErrorInfo(exception.Message, detailBuilder.ToString());
@ -229,7 +229,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
return errorInfo; return errorInfo;
} }
protected virtual void AddExceptionToDetails(Exception exception, StringBuilder detailBuilder, bool enableStackTrace) protected virtual void AddExceptionToDetails(Exception exception, StringBuilder detailBuilder, bool sendStackTraceToClients)
{ {
//Exception Message //Exception Message
detailBuilder.AppendLine(exception.GetType().Name + ": " + exception.Message); detailBuilder.AppendLine(exception.GetType().Name + ": " + exception.Message);
@ -256,7 +256,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
} }
//Exception StackTrace //Exception StackTrace
if (enableStackTrace && !string.IsNullOrEmpty(exception.StackTrace)) if (sendStackTraceToClients && !string.IsNullOrEmpty(exception.StackTrace))
{ {
detailBuilder.AppendLine("STACK TRACE: " + exception.StackTrace); detailBuilder.AppendLine("STACK TRACE: " + exception.StackTrace);
} }
@ -264,7 +264,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
//Inner exception //Inner exception
if (exception.InnerException != null) if (exception.InnerException != null)
{ {
AddExceptionToDetails(exception.InnerException, detailBuilder, enableStackTrace); AddExceptionToDetails(exception.InnerException, detailBuilder, sendStackTraceToClients);
} }
//Inner exceptions for AggregateException //Inner exceptions for AggregateException
@ -278,7 +278,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
foreach (var innerException in aggException.InnerExceptions) 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 return new AbpExceptionHandlingOptions
{ {
SendExceptionsDetailsToClients = false, SendExceptionsDetailsToClients = false,
EnableStackTrace = false SendStackTraceToClients = true
}; };
} }
} }

Loading…
Cancel
Save