mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 22:07:13 -04:00
Apply suggestions and add URL to log message
This commit is contained in:
parent
3ef8448a51
commit
c6eebca335
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net.Mime;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
@ -22,15 +23,15 @@ namespace Jellyfin.Server.Middleware
|
|||||||
/// Initializes a new instance of the <see cref="ExceptionMiddleware"/> class.
|
/// Initializes a new instance of the <see cref="ExceptionMiddleware"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="next">Next request delegate.</param>
|
/// <param name="next">Next request delegate.</param>
|
||||||
/// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
|
/// <param name="logger">Instance of the <see cref="ILogger{ExceptionMiddleware}"/> interface.</param>
|
||||||
/// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
|
/// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
|
||||||
public ExceptionMiddleware(
|
public ExceptionMiddleware(
|
||||||
RequestDelegate next,
|
RequestDelegate next,
|
||||||
ILoggerFactory loggerFactory,
|
ILogger<ExceptionMiddleware> logger,
|
||||||
IServerConfigurationManager serverConfigurationManager)
|
IServerConfigurationManager serverConfigurationManager)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_logger = loggerFactory.CreateLogger<ExceptionMiddleware>();
|
_logger = logger;
|
||||||
_configuration = serverConfigurationManager;
|
_configuration = serverConfigurationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,9 +55,14 @@ namespace Jellyfin.Server.Middleware
|
|||||||
}
|
}
|
||||||
|
|
||||||
ex = GetActualException(ex);
|
ex = GetActualException(ex);
|
||||||
_logger.LogError(ex, "Error processing request: {0}", ex.Message);
|
_logger.LogError(
|
||||||
|
ex,
|
||||||
|
"Error processing request: {ExceptionMessage}. URL {Method} {Url}. ",
|
||||||
|
ex.Message,
|
||||||
|
context.Request.Method,
|
||||||
|
context.Request.Path);
|
||||||
context.Response.StatusCode = GetStatusCode(ex);
|
context.Response.StatusCode = GetStatusCode(ex);
|
||||||
context.Response.ContentType = "text/plain";
|
context.Response.ContentType = MediaTypeNames.Text.Plain;
|
||||||
|
|
||||||
var errorContent = NormalizeExceptionMessage(ex.Message);
|
var errorContent = NormalizeExceptionMessage(ex.Message);
|
||||||
await context.Response.WriteAsync(errorContent).ConfigureAwait(false);
|
await context.Response.WriteAsync(errorContent).ConfigureAwait(false);
|
||||||
@ -105,16 +111,14 @@ namespace Jellyfin.Server.Middleware
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Strip any information we don't want to reveal
|
// Strip any information we don't want to reveal
|
||||||
msg = msg.Replace(
|
return msg.Replace(
|
||||||
_configuration.ApplicationPaths.ProgramSystemPath,
|
_configuration.ApplicationPaths.ProgramSystemPath,
|
||||||
string.Empty,
|
string.Empty,
|
||||||
StringComparison.OrdinalIgnoreCase);
|
StringComparison.OrdinalIgnoreCase)
|
||||||
msg = msg.Replace(
|
.Replace(
|
||||||
_configuration.ApplicationPaths.ProgramDataPath,
|
_configuration.ApplicationPaths.ProgramDataPath,
|
||||||
string.Empty,
|
string.Empty,
|
||||||
StringComparison.OrdinalIgnoreCase);
|
StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
return msg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user