diff --git a/examples/IIS-Example.ps1 b/examples/IIS-Example.ps1 index df61a6394..2634168ba 100644 --- a/examples/IIS-Example.ps1 +++ b/examples/IIS-Example.ps1 @@ -10,7 +10,6 @@ .EXAMPLE To run the sample: ./IIS-Example.ps1 - Invoke-RestMethod -Uri http://localhost:8081 -Method Get Invoke-RestMethod -Uri http://localhost:8081/run-task -Method Get @@ -43,11 +42,13 @@ catch { throw } # create a server, and start listening on port 8081 Start-PodeServer { - - # listen on localhost:8081 + # listen on localhost:8081 or HTTP_PLATFORM_PORT for httpPlatformHandler Add-PodeEndpoint -Address localhost -Port 8081 -Protocol Http - New-PodeLoggingMethod -Terminal | Enable-PodeRequestLogging - New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging + # Add-PodeEndpoint -Address localhost -Port $env:HTTP_PLATFORM_PORT -Protocol Http + + # enable logging to file + New-PodeLoggingMethod -File -Name 'requests' | Enable-PodeRequestLogging + New-PodeLoggingMethod -File -Name 'errors' | Enable-PodeErrorLogging # Add-PodeLimitAccessRule -Name 'DenyLocal' -Action Deny -Component @( # New-PodeLimitIPComponent -IP localhost -Location XForwardedFor diff --git a/examples/web.config b/examples/web.config index 605bdc085..e0e047da8 100644 --- a/examples/web.config +++ b/examples/web.config @@ -1,8 +1,11 @@ - + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Listener/Protocols/Common/Requests/PodeRequestHandler.cs b/src/Listener/Protocols/Common/Requests/PodeRequestHandler.cs index bde6012a0..6d5477f8f 100644 --- a/src/Listener/Protocols/Common/Requests/PodeRequestHandler.cs +++ b/src/Listener/Protocols/Common/Requests/PodeRequestHandler.cs @@ -298,13 +298,6 @@ public async Task Receive(CancellationToken cancellationToken) { PodeHelpers.WriteException(ex, Context.Listener, PodeLoggingLevel.Verbose); } - catch (IOException ex) - { - if (Context.Listener.IsConnected) - { - PodeHelpers.WriteException(ex, Context.Listener, PodeLoggingLevel.Debug); - } - } catch (ObjectDisposedException ex) { if (Context.Listener.IsConnected) @@ -316,26 +309,32 @@ public async Task Receive(CancellationToken cancellationToken) { if (Context.Listener.IsConnected) { - PodeHelpers.WriteException(ex, Context.Listener, PodeLoggingLevel.Error); Error = Strategy.CreateException(ex, PodeRequestStatusType.ServerError); } } catch (PodeRequestException ex) { - PodeHelpers.WriteException(ex, Context.Listener, PodeLoggingLevel.Error); Error = ex; } + catch (Exception ex) when (ex is IOException || ex is ObjectDisposedException) + { + // let the calling method handle these exceptions + throw; + } catch (Exception ex) { - PodeHelpers.WriteException(ex, Context.Listener, PodeLoggingLevel.Error); - Error = Strategy.CreateException(ex, PodeRequestStatusType.ServerError); + // unexpected exception, log and return a generic error response + if (Context.Listener.IsConnected) + { + Error = Strategy.CreateException(ex, PodeRequestStatusType.ServerError); + } } finally { PartialDispose(); } - return false; + return true; } ///