Skip to content

Commit 5d11b5d

Browse files
fix: modules losing data after HTTP 304 responses (#4180)
When a server responds with 304 (nothing changed since last fetch), the response has no body. Several modules were trying to parse that empty body anyway - which either cleared their cached data or threw an exception. The result: a blank calendar, empty newsfeed, or missing weather data after the next refresh cycle. This was reported in the forum: https://forum.magicmirror.builders/topic/20250/calendar-events-broadcasting-nothing-showing The bug was "introduced" by #4120, which correctly started forwarding 304s to consumers - but not all were ready for it. ### Fix Skip parsing on 304 and keep the existing data as-is: - **calendar** - re-broadcasts cached events - **newsfeed** - re-broadcasts cached items - **buienradar, openmeteo, weatherflow, weathergov** - return early before calling `response.json()`
1 parent 3fd1591 commit 5d11b5d

12 files changed

Lines changed: 152 additions & 0 deletions

File tree

‎defaultmodules/calendar/calendarfetcher.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ class CalendarFetcher {
5151
*/
5252
async #handleResponse (response) {
5353
try {
54+
// 304 Not Modified has no body: keep previously fetched events and just re-broadcast them.
55+
if (response.status === 304) {
56+
this.lastFetch = Date.now();
57+
this.broadcastEvents();
58+
return;
59+
}
60+
5461
const responseData = await response.text();
5562
const parsed = await ical.async.parseICS(responseData);
5663

‎defaultmodules/newsfeed/newsfeedfetcher.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ class NewsfeedFetcher {
6868
* @param {Response} response - The fetch Response object
6969
*/
7070
async #handleResponse (response) {
71+
// 304 Not Modified has no body: keep previously fetched items and re-broadcast them.
72+
if (response.status === 304) {
73+
this.broadcastItems();
74+
return;
75+
}
76+
7177
this.items = [];
7278
const parser = new FeedMe();
7379

‎defaultmodules/weather/providers/buienradar.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class BuienradarProvider {
111111
});
112112

113113
this.fetcher.on("response", async (response) => {
114+
if (response.status === 304) return;
114115
try {
115116
const data = await response.json();
116117
this.#handleResponse(data);

‎defaultmodules/weather/providers/envcanada.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class EnvCanadaProvider {
6969
});
7070

7171
this.fetcher.on("response", async (response) => {
72+
if (response.status === 304) return;
7273
try {
7374
// Check if hour changed - restart fetcher with new URL
7475
const newHour = new Date().toISOString().substring(11, 13);

‎defaultmodules/weather/providers/openmeteo.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class OpenMeteoProvider {
172172
});
173173

174174
this.fetcher.on("response", async (response) => {
175+
if (response.status === 304) return;
175176
try {
176177
const data = await response.json();
177178
this.#handleResponse(data);

‎defaultmodules/weather/providers/openweathermap.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class OpenWeatherMapProvider {
7373
});
7474

7575
this.fetcher.on("response", async (response) => {
76+
if (response.status === 304) return;
7677
try {
7778
const data = await response.json();
7879
this.#handleResponse(data);

‎defaultmodules/weather/providers/pirateweather.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class PirateweatherProvider {
5252
});
5353

5454
this.fetcher.on("response", async (response) => {
55+
if (response.status === 304) return;
5556
try {
5657
const data = await response.json();
5758
this.#handleResponse(data);

‎defaultmodules/weather/providers/smhi.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class SMHIProvider {
9595
});
9696

9797
this.fetcher.on("response", async (response) => {
98+
if (response.status === 304) return;
9899
try {
99100
const data = await response.json();
100101
this.#handleResponse(data);

‎defaultmodules/weather/providers/ukmetofficedatahub.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class UkMetOfficeDataHubProvider {
6464
});
6565

6666
this.fetcher.on("response", async (response) => {
67+
if (response.status === 304) return;
6768
try {
6869
const data = await response.json();
6970
this.#handleResponse(data);

‎defaultmodules/weather/providers/weatherflow.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class WeatherFlowProvider {
7474
});
7575

7676
this.fetcher.on("response", async (response) => {
77+
if (response.status === 304) return;
7778
try {
7879
const data = await response.json();
7980
const processed = this.#processData(data);

0 commit comments

Comments
 (0)