Badgerati / Pode

Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
https://badgerati.github.io/Pode
MIT License
866 stars 92 forks source link

HTTP Request Timeout Logs Unnecessary Errors to Console #1437

Closed mdaneri closed 1 month ago

mdaneri commented 1 month ago

Description: When an HTTP request times out in Pode, an error message is unnecessarily written to the console, even though the timeout is expected behavior. This results in a cluttered log output, making it harder to identify genuine issues.

Steps to Reproduce:

  1. Trigger an HTTP request that will exceed the timeout threshold.
  2. Observe the console/logs for error messages.

Expected Behavior: Timeouts should not be logged as errors unless there is an unexpected issue related to the timeout.

Actual Behavior: An error message appears on the console each time an HTTP request times out, despite this being an expected event.

Fix Implemented: Modified the PodeSocket.HandleContext method to prevent logging HTTP request timeout errors:

if (context.CloseImmediately)
{
    // Check if the error is not an HttpRequestException with a message starting with "Request timeout".
    if (!(context.Request.Error is HttpRequestException httpRequestException) || !httpRequestException.Message.StartsWith("Request timeout"))
    {
        PodeHelpers.WriteException(context.Request.Error, Listener);
    }
    context.Dispose(true);
    process = false;
}

The addition of the condition !httpRequestException.Message.StartsWith("Request timeout") ensures that only non-timeout-related exceptions are logged, reducing unnecessary console output.