Skip to content

Commit

Permalink
Rename EnableStackTrace to SendStackTraceToClients
Browse files Browse the repository at this point in the history
  • Loading branch information
berkansasmaz committed Nov 11, 2021
1 parent f75747e commit 3ce989e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 31 deletions.
4 changes: 2 additions & 2 deletions docs/en/Exception-Handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,12 @@ You can also throw these type of exceptions in your code (although it's rarely n
Configure<AbpExceptionHandlingOptions>(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.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected virtual RemoteServiceErrorInfo GetErrorInfo(UserExceptionInformerConte
return ExceptionToErrorInfoConverter.Convert(context.Exception, options =>
{
options.SendExceptionsDetailsToClients = Options.SendExceptionsDetailsToClients;
options.EnableStackTrace = Options.EnableStackTrace;
options.SendStackTraceToClients = Options.SendStackTraceToClients;
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task<IActionResult> Index(int httpStatusCode)
var errorInfo = _errorInfoConverter.Convert(exception, options =>
{
options.SendExceptionsDetailsToClients = _exceptionHandlingOptions.SendExceptionsDetailsToClients;
options.EnableStackTrace = _exceptionHandlingOptions.EnableStackTrace;
options.SendStackTraceToClients = _exceptionHandlingOptions.SendStackTraceToClients;
});

if (httpStatusCode == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected virtual async Task HandleAndWrapException(ExceptionContext context)
var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, options =>
{
options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients;
options.EnableStackTrace = exceptionHandlingOptions.EnableStackTrace;
options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients;
});

var logLevel = context.Exception.GetLogLevel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected virtual async Task HandleAndWrapException(PageHandlerExecutedContext c
var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, options =>
{
options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients;
options.EnableStackTrace = exceptionHandlingOptions.EnableStackTrace;
options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients;
});

var logLevel = context.Exception.GetLogLevel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ await httpContext.RequestServices.GetRequiredService<IAbpAuthorizationExceptionH
errorInfoConverter.Convert(exception, options =>
{
options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients;
options.EnableStackTrace = exceptionHandlingOptions.EnableStackTrace;
options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients;
})
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public RemoteServiceErrorInfo Convert(Exception exception, bool includeSensitive
{
var exceptionHandlingOptions = CreateDefaultOptions();
exceptionHandlingOptions.SendExceptionsDetailsToClients = includeSensitiveDetails;
exceptionHandlingOptions.EnableStackTrace = includeSensitiveDetails;
exceptionHandlingOptions.SendStackTraceToClients = includeSensitiveDetails;

var errorInfo = CreateErrorInfoWithoutCode(exception, exceptionHandlingOptions);

Expand Down Expand Up @@ -73,7 +73,7 @@ protected virtual RemoteServiceErrorInfo CreateErrorInfoWithoutCode(Exception ex
{
if (options.SendExceptionsDetailsToClients)
{
return CreateDetailedErrorInfoFromException(exception, options.EnableStackTrace);
return CreateDetailedErrorInfoFromException(exception, options.SendStackTraceToClients);
}

exception = TryToGetActualException(exception);
Expand Down Expand Up @@ -213,11 +213,11 @@ protected virtual Exception TryToGetActualException(Exception exception)
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());

Expand All @@ -229,7 +229,7 @@ protected virtual RemoteServiceErrorInfo CreateDetailedErrorInfoFromException(Ex
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);
Expand All @@ -256,15 +256,15 @@ protected virtual void AddExceptionToDetails(Exception exception, StringBuilder
}

//Exception StackTrace
if (enableStackTrace && !string.IsNullOrEmpty(exception.StackTrace))
if (sendStackTraceToClients && !string.IsNullOrEmpty(exception.StackTrace))
{
detailBuilder.AppendLine("STACK TRACE: " + exception.StackTrace);
}

//Inner exception
if (exception.InnerException != null)
{
AddExceptionToDetails(exception.InnerException, detailBuilder, enableStackTrace);
AddExceptionToDetails(exception.InnerException, detailBuilder, sendStackTraceToClients);
}

//Inner exceptions for AggregateException
Expand All @@ -278,7 +278,7 @@ protected virtual void AddExceptionToDetails(Exception exception, StringBuilder

foreach (var innerException in aggException.InnerExceptions)
{
AddExceptionToDetails(innerException, detailBuilder, enableStackTrace);
AddExceptionToDetails(innerException, detailBuilder, sendStackTraceToClients);
}
}
}
Expand Down Expand Up @@ -321,7 +321,7 @@ protected virtual AbpExceptionHandlingOptions CreateDefaultOptions()
return new AbpExceptionHandlingOptions
{
SendExceptionsDetailsToClients = false,
EnableStackTrace = false
SendStackTraceToClients = true
};
}
}
Expand Down

0 comments on commit 3ce989e

Please sign in to comment.