Allow HTTPFetcher to pass through 304 responses#4120
Draft
sonnyb9 wants to merge 1 commit intoMagicMirrorOrg:masterfrom
Draft
Allow HTTPFetcher to pass through 304 responses#4120sonnyb9 wants to merge 1 commit intoMagicMirrorOrg:masterfrom
sonnyb9 wants to merge 1 commit intoMagicMirrorOrg:masterfrom
Conversation
Collaborator
|
Please base your PR against the develop branch |
| if (response.status === 304) { | ||
| // Allow providers with cache-aware handling to reuse prior data. | ||
| this.emit("response", response); | ||
| } else if (!response.ok) { |
Collaborator
There was a problem hiding this comment.
This would skip the error count reset for 304s - but a 304 means the server is healthy, so serverErrorCount/networkErrorCount should still be cleared.
This would fix that:
const isSuccessfulResponse = response.ok || response.status === 304;
if (!isSuccessfulResponse) {The reset would happen in the else branch.
Additionally, we could even reverse the if condition to handle the happy path first, which would make the code even easier to understand. That wouldn't strictly fall within the scope of this PR, but it would be a small refactoring that I would consider as a minor acceptable tweak.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This updates
js/http_fetcher.jsso HTTP304 Not Modifiedresponses are emitted through the normalresponseevent instead of being treated as errors.That aligns the core fetcher with the built-in
yrweather provider inv2.35.0, which already includes explicit logic to handle304and reuse cached data.Closes #4119.
Root cause
HTTPFetchercurrently treats all non-OK responses as errors. Since304is not an OK response, it never reaches providers listening on theresponseevent.At the same time,
defaultmodules/weather/providers/yr.jsexpects to receive304and handle it by reusing cached data.What changed
304inHTTPFetcher304through the normalresponseeventValidation
defaultmodules/weather/providers/yr.jsalready expectsresponse.status === 304v2.35.0HTTPFetcherbehavior to the provider logicnode --check js/http_fetcher.js