Skip to content

Comments

fix: version check error if not connection#284

Merged
prom3theu5 merged 1 commit intoprom3theu5:mainfrom
vdboots:Offline-Access-Nuget-Crash
Feb 14, 2025
Merged

fix: version check error if not connection#284
prom3theu5 merged 1 commit intoprom3theu5:mainfrom
vdboots:Offline-Access-Nuget-Crash

Conversation

@vdboots
Copy link
Contributor

@vdboots vdboots commented Feb 6, 2025

User description

fixes issues where application will crash if there is no connection available.


PR Type

Bug fix


Description

  • Fixed crash when no internet connection during version check.

  • Added specific handling for HttpRequestException in VersionCheckService.


Changes walkthrough 📝

Relevant files
Error handling
VersionCheckService.cs
Added error handling for network issues in version check 

src/Aspirate.Services/Implementations/VersionCheckService.cs

  • Added a catch block for HttpRequestException.
  • Logged a user-friendly message for network errors.
  • Prevented application crash when unable to reach api.nuget.org.
  • +5/-0     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @qodo-code-review
    Copy link

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The new catch block for HttpRequestException swallows the exception details. Consider logging the exception details for debugging purposes.

    catch (HttpRequestException)
    {
        logger.MarkupLine($"[red]Network error: Unable to reach api.nuget.org. Please check your internet connection.[/]");
        return;
    }

    @qodo-code-review
    Copy link

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Improve network error handling specificity

    Add specific HTTP status code handling in the catch block to provide more
    precise error messages for different network scenarios (e.g., 404, 503,
    timeout).

    src/Aspirate.Services/Implementations/VersionCheckService.cs [150-154]

    -catch (HttpRequestException)
    +catch (HttpRequestException ex)
     {
    -    logger.MarkupLine($"[red]Network error: Unable to reach api.nuget.org. Please check your internet connection.[/]");
    +    var message = ex.StatusCode switch
    +    {
    +        System.Net.HttpStatusCode.NotFound => "NuGet API endpoint not found",
    +        System.Net.HttpStatusCode.ServiceUnavailable => "NuGet API is temporarily unavailable",
    +        _ => "Unable to reach api.nuget.org. Please check your internet connection"
    +    };
    +    logger.MarkupLine($"[red]Network error: {message}[/]");
         return;
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion enhances error handling by providing more specific error messages based on HTTP status codes, improving the user experience by giving clearer feedback about the nature of network failures.

    Medium

    @prom3theu5 prom3theu5 merged commit bbf3617 into prom3theu5:main Feb 14, 2025
    @prom3theu5
    Copy link
    Owner

    Good catch

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants