mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-08 10:44:23 -04:00
Merge pull request #1870 from JustAMan/fix-http-ex1
Fix exception when handling error, log errors better (cherry picked from commit d8d2e52e3ffaa59a32cc2cbb4997022b979f9ca0) Signed-off-by: Joshua Boniface <joshua@boniface.me>
This commit is contained in:
parent
89d365122c
commit
0212c0b85f
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1,3 +1,5 @@
|
|||||||
* text=auto eol=lf
|
* text=auto eol=lf
|
||||||
|
*.png binary
|
||||||
|
*.jpg binary
|
||||||
|
|
||||||
CONTRIBUTORS.md merge=union
|
CONTRIBUTORS.md merge=union
|
||||||
|
@ -224,7 +224,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
|
try
|
||||||
{
|
{
|
||||||
@ -234,9 +234,9 @@ namespace Emby.Server.Implementations.HttpServer
|
|||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error processing request");
|
_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;
|
var httpRes = httpReq.Response;
|
||||||
@ -249,8 +249,10 @@ namespace Emby.Server.Implementations.HttpServer
|
|||||||
var statusCode = GetStatusCode(ex);
|
var statusCode = GetStatusCode(ex);
|
||||||
httpRes.StatusCode = statusCode;
|
httpRes.StatusCode = statusCode;
|
||||||
|
|
||||||
httpRes.ContentType = "text/html";
|
var errContent = NormalizeExceptionMessage(ex.Message);
|
||||||
await httpRes.WriteAsync(NormalizeExceptionMessage(ex.Message)).ConfigureAwait(false);
|
httpRes.ContentType = "text/plain";
|
||||||
|
httpRes.ContentLength = errContent.Length;
|
||||||
|
await httpRes.WriteAsync(errContent).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception errorEx)
|
catch (Exception errorEx)
|
||||||
{
|
{
|
||||||
@ -518,22 +520,22 @@ namespace Emby.Server.Implementations.HttpServer
|
|||||||
}
|
}
|
||||||
else
|
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)
|
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)
|
catch (SecurityException ex)
|
||||||
{
|
{
|
||||||
await ErrorHandler(ex, httpReq, false, true).ConfigureAwait(false);
|
await ErrorHandler(ex, httpReq, false).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var logException = !string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase);
|
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
|
finally
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user