aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2019-10-09 16:08:50 +0200
committerGitHub <noreply@github.com>2019-10-09 16:08:50 +0200
commitd8d2e52e3ffaa59a32cc2cbb4997022b979f9ca0 (patch)
tree524a1a523b427f49b06a50bc802aef09cfda9748
parent8d7ac291bc3a11bae520fdf0b9233e8a68734e5d (diff)
parent03450f383ffe24d742ffa68c99c70b426081db52 (diff)
Merge pull request #1870 from JustAMan/fix-http-ex1
Fix exception when handling error, log errors better
-rw-r--r--.gitattributes2
-rw-r--r--Emby.Server.Implementations/HttpServer/HttpListenerHost.cs20
2 files changed, 13 insertions, 9 deletions
diff --git a/.gitattributes b/.gitattributes
index d78b0459d..8ae599725 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,3 +1,5 @@
* text=auto eol=lf
+*.png binary
+*.jpg binary
CONTRIBUTORS.md merge=union
diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
index d60f5c055..6f436be94 100644
--- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
+++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
@@ -208,7 +208,7 @@ namespace Emby.Server.Implementations.HttpServer
}
}
- private async Task ErrorHandler(Exception ex, IRequest httpReq, bool logExceptionStackTrace, bool logExceptionMessage)
+ private async Task ErrorHandler(Exception ex, IRequest httpReq, bool logExceptionStackTrace)
{
try
{
@@ -218,9 +218,9 @@ namespace Emby.Server.Implementations.HttpServer
{
_logger.LogError(ex, "Error processing request");
}
- else if (logExceptionMessage)
+ else
{
- _logger.LogError(ex.Message);
+ _logger.LogError("Error processing request: {Message}", ex.Message);
}
var httpRes = httpReq.Response;
@@ -233,8 +233,10 @@ namespace Emby.Server.Implementations.HttpServer
var statusCode = GetStatusCode(ex);
httpRes.StatusCode = statusCode;
- httpRes.ContentType = "text/html";
- await httpRes.WriteAsync(NormalizeExceptionMessage(ex.Message)).ConfigureAwait(false);
+ var errContent = NormalizeExceptionMessage(ex.Message);
+ httpRes.ContentType = "text/plain";
+ httpRes.ContentLength = errContent.Length;
+ await httpRes.WriteAsync(errContent).ConfigureAwait(false);
}
catch (Exception errorEx)
{
@@ -509,22 +511,22 @@ namespace Emby.Server.Implementations.HttpServer
}
else
{
- await ErrorHandler(new FileNotFoundException(), httpReq, false, false).ConfigureAwait(false);
+ await ErrorHandler(new FileNotFoundException(), httpReq, false).ConfigureAwait(false);
}
}
catch (Exception ex) when (ex is SocketException || ex is IOException || ex is OperationCanceledException)
{
- await ErrorHandler(ex, httpReq, false, false).ConfigureAwait(false);
+ await ErrorHandler(ex, httpReq, false).ConfigureAwait(false);
}
catch (SecurityException ex)
{
- await ErrorHandler(ex, httpReq, false, true).ConfigureAwait(false);
+ await ErrorHandler(ex, httpReq, false).ConfigureAwait(false);
}
catch (Exception ex)
{
var logException = !string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase);
- await ErrorHandler(ex, httpReq, logException, false).ConfigureAwait(false);
+ await ErrorHandler(ex, httpReq, logException).ConfigureAwait(false);
}
finally
{