aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <daullmer@gmail.com>2020-05-26 16:55:27 +0200
committerDavid <daullmer@gmail.com>2020-05-26 16:55:27 +0200
commita5a39300bc733ad7b1d3c683f5f290a742171661 (patch)
treeef092b28f32437e528f653e5c48ad9817f65b708
parent5c9503723441826960234364347dc84ebd04ade7 (diff)
Don't send Exception message in Production Environment
-rw-r--r--Jellyfin.Server/Middleware/ExceptionMiddleware.cs16
1 files changed, 15 insertions, 1 deletions
diff --git a/Jellyfin.Server/Middleware/ExceptionMiddleware.cs b/Jellyfin.Server/Middleware/ExceptionMiddleware.cs
index 0d79bbfaf..dd4d1ee99 100644
--- a/Jellyfin.Server/Middleware/ExceptionMiddleware.cs
+++ b/Jellyfin.Server/Middleware/ExceptionMiddleware.cs
@@ -7,7 +7,9 @@ using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Authentication;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net;
+using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Server.Middleware
@@ -20,6 +22,7 @@ namespace Jellyfin.Server.Middleware
private readonly RequestDelegate _next;
private readonly ILogger<ExceptionMiddleware> _logger;
private readonly IServerConfigurationManager _configuration;
+ private readonly IWebHostEnvironment _hostEnvironment;
/// <summary>
/// Initializes a new instance of the <see cref="ExceptionMiddleware"/> class.
@@ -27,14 +30,17 @@ namespace Jellyfin.Server.Middleware
/// <param name="next">Next request delegate.</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="hostEnvironment">Instance of the <see cref="IWebHostEnvironment"/> interface.</param>
public ExceptionMiddleware(
RequestDelegate next,
ILogger<ExceptionMiddleware> logger,
- IServerConfigurationManager serverConfigurationManager)
+ IServerConfigurationManager serverConfigurationManager,
+ IWebHostEnvironment hostEnvironment)
{
_next = next;
_logger = logger;
_configuration = serverConfigurationManager;
+ _hostEnvironment = hostEnvironment;
}
/// <summary>
@@ -85,6 +91,14 @@ namespace Jellyfin.Server.Middleware
context.Response.StatusCode = GetStatusCode(ex);
context.Response.ContentType = MediaTypeNames.Text.Plain;
+
+ // Don't send exception unless the server is in a Development environment
+ if (!_hostEnvironment.IsDevelopment())
+ {
+ await context.Response.WriteAsync("Error processing request.").ConfigureAwait(false);
+ return;
+ }
+
var errorContent = NormalizeExceptionMessage(ex.Message);
await context.Response.WriteAsync(errorContent).ConfigureAwait(false);
}