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

Fixes the unnecessary Error Logging on HTTP Request Timeouts #1438

Closed mdaneri closed 1 month ago

mdaneri commented 1 month ago

Linked Issue: #1437 - HTTP Request Timeout Logs Unnecessary Errors to Console

Description: This pull request addresses issue #1437, where unnecessary error messages were being logged to the console when HTTP requests timed out. The current behavior resulted in cluttered logs, making it difficult to differentiate between expected timeouts and actual errors that require attention.

Changes Made:

  1. Fix for Error Logging on Request Timeout:

    • Updated the PodeSocket.HandleContext method to add a condition that prevents logging exceptions for HTTP request timeouts.
    • Specifically, modified the context.CloseImmediately block to check if the exception is an HttpRequestException with a message starting with "Request timeout". If so, the error is no longer logged, as this is expected behavior.

    Code Snippet:

    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;
    }
  2. Code Improvements:

    • Comments and Headers: Added comprehensive comments and XML documentation headers to the following files for better code readability and maintainability:
      • PodeSocket.cs
      • PodeRequest.cs
      • PodeContext.cs
    • Additional Logs: Introduced additional logging to provide better insights into key actions and errors during socket, request, and context handling.
    • Optimizations: Made several small optimizations to improve the performance and stability of socket and context handling.

Impact: