diff options
| author | crobibero <cody@robibe.ro> | 2020-06-13 15:20:13 -0600 |
|---|---|---|
| committer | crobibero <cody@robibe.ro> | 2020-06-13 15:20:13 -0600 |
| commit | bcce8190ffe6cf2b4926c64bca98b8266c0937b0 (patch) | |
| tree | 7008786b1e0631445437f451cc6422b4be9a5f0d /Jellyfin.Server/Middleware/ExceptionMiddleware.cs | |
| parent | 88b6c26472ad57822d3ab79a043db259ffcbb0e3 (diff) | |
| parent | 0011e8df47380936742302ef40639a4626a780ed (diff) | |
Merge remote-tracking branch 'upstream/api-migration' into api-channel
Diffstat (limited to 'Jellyfin.Server/Middleware/ExceptionMiddleware.cs')
| -rw-r--r-- | Jellyfin.Server/Middleware/ExceptionMiddleware.cs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Jellyfin.Server/Middleware/ExceptionMiddleware.cs b/Jellyfin.Server/Middleware/ExceptionMiddleware.cs index 0d79bbfaf..63effafc1 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,7 +91,11 @@ namespace Jellyfin.Server.Middleware context.Response.StatusCode = GetStatusCode(ex); context.Response.ContentType = MediaTypeNames.Text.Plain; - var errorContent = NormalizeExceptionMessage(ex.Message); + + // Don't send exception unless the server is in a Development environment + var errorContent = _hostEnvironment.IsDevelopment() + ? NormalizeExceptionMessage(ex.Message) + : "Error processing request."; await context.Response.WriteAsync(errorContent).ConfigureAwait(false); } } |
