Skip to content

Conversation

jvoisin
Copy link
Collaborator

@jvoisin jvoisin commented Aug 29, 2025

  • Replace a strings.HasPrefix + strings.Cut with a call to strings.CutPrefix.
  • Instead of enumerating all possible redirection code, check if the code is 300-something.
  • Extract an error constructor outside of its current scope instead of duplicating it 5 times
  • Use constant strings for LocalizedError's return values where possible.

@fguillot fguillot requested a review from Copilot September 10, 2025 03:28
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR applies several minor refactoring improvements to the response handler fetcher code to make it more readable and maintainable.

  • Modernizes string processing by using strings.CutPrefix and strings.SplitSeq
  • Simplifies HTTP redirect detection with status code range checking
  • Eliminates code duplication by extracting error construction logic

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

- Replace a strings.HasPrefix + strings.Cut with a call to strings.CutPrefix.
- Instead of enumerating all possible redirection code, check if the code is
  300-something.
- Extract an error constructor outside of its current scope instead of
  duplicating it 5 times
- Use constant strings for LocalizedError's return values where possible.
r.httpResponse.StatusCode == http.StatusSeeOther ||
r.httpResponse.StatusCode == http.StatusTemporaryRedirect ||
r.httpResponse.StatusCode == http.StatusPermanentRedirect)
return r.httpResponse != nil && r.httpResponse.StatusCode >= 300 && r.httpResponse.StatusCode < 400
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct because some status codes in the 3xx range are not redirects. For example: 304 / StatusNotModified is not a redirect.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's technically a redirect, as it's a redirection to the local cache, which shouldn't happen in our use-case anyway, since the only place we're making use of IsRedirect is for // Do not add redirections to the possible list of subscriptions to avoid confusion.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants