Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor FXIOS-11063 Improve how we handle failing network requests to retrieve favicon URL and images #24282

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bmihai23
Copy link
Contributor

@bmihai23 bmihai23 commented Jan 22, 2025

📜 Tickets

Jira ticket
Github issue

💡 Description

  • This PR is a WIP and I’ve opened it as a draft to gather feedback.
  • It introduces caching for certain errors (5xx) to prevent repeated slow network calls during server downtimes.
  • This allows the app to retry the request when the server becomes available again.

📝 Checklist

You have to check all boxes before merging

  • Filled in the above information (tickets numbers and description of your work)
  • Updated the PR name to follow our PR naming guidelines
  • Wrote unit tests and/or ensured the tests suite is passing
  • When working on UI, I checked and implemented accessibility (minimum Dynamic Text and VoiceOver)
  • If needed, I updated documentation / comments for complex code and public methods
  • If needed, added a backport comment (example @Mergifyio backport release/v120)

@@ -38,6 +38,12 @@ struct DefaultFaviconURLHandler: FaviconURLHandler {
await urlCache.cacheURL(cacheKey: model.cacheKey, faviconURL: url)
return url
} catch {
let isServerError = ServerErrorHelper.extractServerError(error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have unit tests for this? You might have to remove the ServerErrorHelper being static to do so

@@ -117,7 +117,13 @@ class DefaultImageHandler: ImageHandler {
await imageCache.cacheImage(image: image, cacheKey: imageModel.cacheKey, type: imageModel.imageType)
return image
} catch {
return await fallbackToLetterFavicon(imageModel: imageModel)
let isServerError = ServerErrorHelper.extractServerError(error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unit tests for this as well and the fallbackToLetterFavicon code would be awesome 🙏

@lmarceau lmarceau requested a review from ih-codes January 22, 2025 14:59
Copy link
Collaborator

@FilippoZazzeroni FilippoZazzeroni left a comment

Choose a reason for hiding this comment

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

LGTM 🎉 great work just some minor things. Also as @lmarceau would be nice to have test coverage for the changes

let isServerError = ServerErrorHelper.extractServerError(error)

if isServerError {
return await fallbackToLetterFavicon(imageModel: imageModel, isServerError: true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we pass directly isServerError to the method ?

return await fallbackToLetterFavicon(imageModel: imageModel, isServerError: isServerError)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants