DO not use developer exception page when exception stack trace should be ignored

This commit is contained in:
Mark Monteiro 2020-05-17 18:07:37 -04:00
parent 4b4b50f3ee
commit 634bc73c9a
1 changed files with 14 additions and 13 deletions

View File

@ -210,16 +210,8 @@ namespace Emby.Server.Implementations.HttpServer
} }
} }
private async Task ErrorHandler(Exception ex, IRequest httpReq, int statusCode, string urlToLog) private async Task ErrorHandler(Exception ex, IRequest httpReq, int statusCode, string urlToLog, bool ignoreStackTrace)
{ {
bool ignoreStackTrace =
ex is SocketException
|| ex is IOException
|| ex is OperationCanceledException
|| ex is SecurityException
|| ex is AuthenticationException
|| ex is FileNotFoundException;
if (ignoreStackTrace) if (ignoreStackTrace)
{ {
_logger.LogError("Error processing request: {Message}. URL: {Url}", ex.Message.TrimEnd('.'), urlToLog); _logger.LogError("Error processing request: {Message}. URL: {Url}", ex.Message.TrimEnd('.'), urlToLog);
@ -504,15 +496,24 @@ namespace Emby.Server.Implementations.HttpServer
{ {
var requestInnerEx = GetActualException(requestEx); var requestInnerEx = GetActualException(requestEx);
var statusCode = GetStatusCode(requestInnerEx); var statusCode = GetStatusCode(requestInnerEx);
bool ignoreStackTrace =
requestInnerEx is SocketException
|| requestInnerEx is IOException
|| requestInnerEx is OperationCanceledException
|| requestInnerEx is SecurityException
|| requestInnerEx is AuthenticationException
|| requestInnerEx is FileNotFoundException;
// Do not handle 500 server exceptions manually when in development mode // Do not handle 500 server exceptions manually when in development mode.
// The framework-defined development exception page will be returned instead // Instead, re-throw the exception so it can be handled by the DeveloperExceptionPageMiddleware.
if (statusCode == 500 && _hostEnvironment.IsDevelopment()) // However, do not use the DeveloperExceptionPageMiddleware when the stack trace should be ignored,
// because it will log the stack trace when it handles the exception.
if (statusCode == 500 && !ignoreStackTrace && _hostEnvironment.IsDevelopment() )
{ {
throw; throw;
} }
await ErrorHandler(requestInnerEx, httpReq, statusCode, urlToLog).ConfigureAwait(false); await ErrorHandler(requestInnerEx, httpReq, statusCode, urlToLog, ignoreStackTrace).ConfigureAwait(false);
} }
catch (Exception handlerException) catch (Exception handlerException)
{ {