diff options
| author | dkanada <dkanada@users.noreply.github.com> | 2020-04-06 18:59:58 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-06 18:59:58 +0900 |
| commit | 0522c90109b2697eaafc38ef27937f1ad87854fa (patch) | |
| tree | 05aeb5429bf7baf757fb99addf9c11c8ba986406 /Emby.Server.Implementations/HttpServer/HttpListenerHost.cs | |
| parent | 19b6961c0890df8461a07039c0a3edbb9a276120 (diff) | |
| parent | cb634d27d8f66ce05d21610226306e80c47af959 (diff) | |
Merge pull request #2635 from mark-monteiro/use-development-exception-page
Use ASP Development Exception Page
Diffstat (limited to 'Emby.Server.Implementations/HttpServer/HttpListenerHost.cs')
| -rw-r--r-- | Emby.Server.Implementations/HttpServer/HttpListenerHost.cs | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 7a812f320..72667a314 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -23,6 +23,7 @@ using MediaBrowser.Model.Services; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using ServiceStack.Text.Jsv; @@ -48,6 +49,8 @@ namespace Emby.Server.Implementations.HttpServer private readonly string _baseUrlPrefix; private readonly Dictionary<Type, Type> _serviceOperationsMap = new Dictionary<Type, Type>(); private readonly List<IWebSocketConnection> _webSocketConnections = new List<IWebSocketConnection>(); + private readonly IHostEnvironment _hostEnvironment; + private IWebSocketListener[] _webSocketListeners = Array.Empty<IWebSocketListener>(); private bool _disposed = false; @@ -61,7 +64,8 @@ namespace Emby.Server.Implementations.HttpServer IXmlSerializer xmlSerializer, IHttpListener socketListener, ILocalizationManager localizationManager, - ServiceController serviceController) + ServiceController serviceController, + IHostEnvironment hostEnvironment) { _appHost = applicationHost; _logger = logger; @@ -75,6 +79,7 @@ namespace Emby.Server.Implementations.HttpServer ServiceController = serviceController; _socketListener.WebSocketConnected = OnWebSocketConnected; + _hostEnvironment = hostEnvironment; _funcParseFn = t => s => JsvReader.GetParseFn(t)(s); @@ -530,22 +535,25 @@ namespace Emby.Server.Implementations.HttpServer } else { - await ErrorHandler(new FileNotFoundException(), httpReq, false).ConfigureAwait(false); + throw new FileNotFoundException(); } } - catch (Exception ex) when (ex is SocketException || ex is IOException || ex is OperationCanceledException) - { - await ErrorHandler(ex, httpReq, false).ConfigureAwait(false); - } - catch (SecurityException ex) - { - await ErrorHandler(ex, httpReq, false).ConfigureAwait(false); - } catch (Exception ex) { - var logException = !string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase); + // Do not handle exceptions manually when in development mode + // The framework-defined development exception page will be returned instead + if (_hostEnvironment.IsDevelopment()) + { + throw; + } - await ErrorHandler(ex, httpReq, logException).ConfigureAwait(false); + bool ignoreStackTrace = + ex is SocketException + || ex is IOException + || ex is OperationCanceledException + || ex is SecurityException + || ex is FileNotFoundException; + await ErrorHandler(ex, httpReq, ignoreStackTrace).ConfigureAwait(false); } finally { |
