mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 03:26:07 +02:00
Merge pull request #3186 from Ullmie02/asp-api-exception
Don't send Exception message in Production Environment
This commit is contained in:
commit
35366772b2
1 changed files with 12 additions and 2 deletions
|
@ -7,7 +7,9 @@ using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Controller.Authentication;
|
using MediaBrowser.Controller.Authentication;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Net;
|
using MediaBrowser.Controller.Net;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Jellyfin.Server.Middleware
|
namespace Jellyfin.Server.Middleware
|
||||||
|
@ -20,6 +22,7 @@ namespace Jellyfin.Server.Middleware
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly ILogger<ExceptionMiddleware> _logger;
|
private readonly ILogger<ExceptionMiddleware> _logger;
|
||||||
private readonly IServerConfigurationManager _configuration;
|
private readonly IServerConfigurationManager _configuration;
|
||||||
|
private readonly IWebHostEnvironment _hostEnvironment;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ExceptionMiddleware"/> class.
|
/// 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="next">Next request delegate.</param>
|
||||||
/// <param name="logger">Instance of the <see cref="ILogger{ExceptionMiddleware}"/> 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>
|
||||||
|
/// <param name="hostEnvironment">Instance of the <see cref="IWebHostEnvironment"/> interface.</param>
|
||||||
public ExceptionMiddleware(
|
public ExceptionMiddleware(
|
||||||
RequestDelegate next,
|
RequestDelegate next,
|
||||||
ILogger<ExceptionMiddleware> logger,
|
ILogger<ExceptionMiddleware> logger,
|
||||||
IServerConfigurationManager serverConfigurationManager)
|
IServerConfigurationManager serverConfigurationManager,
|
||||||
|
IWebHostEnvironment hostEnvironment)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_configuration = serverConfigurationManager;
|
_configuration = serverConfigurationManager;
|
||||||
|
_hostEnvironment = hostEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -85,7 +91,11 @@ namespace Jellyfin.Server.Middleware
|
||||||
|
|
||||||
context.Response.StatusCode = GetStatusCode(ex);
|
context.Response.StatusCode = GetStatusCode(ex);
|
||||||
context.Response.ContentType = MediaTypeNames.Text.Plain;
|
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);
|
await context.Response.WriteAsync(errorContent).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue