diff --git a/js/http_fetcher.js b/js/http_fetcher.js index 0766168401..a1ba138afd 100644 --- a/js/http_fetcher.js +++ b/js/http_fetcher.js @@ -273,7 +273,9 @@ class HTTPFetcher extends EventEmitter { signal: controller.signal }); - if (!response.ok) { + const isSuccessfulResponse = response.ok || response.status === 304; + + if (!isSuccessfulResponse) { const { delay, errorInfo } = this.#getDelayForResponse(response); nextDelay = delay; this.emit("error", errorInfo); diff --git a/tests/unit/functions/http_fetcher_spec.js b/tests/unit/functions/http_fetcher_spec.js index 0d8d41be50..d53cdc9b09 100644 --- a/tests/unit/functions/http_fetcher_spec.js +++ b/tests/unit/functions/http_fetcher_spec.js @@ -51,6 +51,31 @@ describe("HTTPFetcher", () => { expect(text).toBe(responseData); }); + it("should treat 304 responses as successful and reset error counters", async () => { + server.use( + http.get(TEST_URL, () => { + return new HttpResponse(null, { status: 304 }); + }) + ); + + fetcher = new HTTPFetcher(TEST_URL, { reloadInterval: 60000 }); + fetcher.serverErrorCount = 2; + fetcher.networkErrorCount = 3; + + const responsePromise = new Promise((resolve) => { + fetcher.on("response", (response) => { + resolve(response); + }); + }); + + fetcher.startPeriodicFetch(); + const response = await responsePromise; + + expect(response.status).toBe(304); + expect(fetcher.serverErrorCount).toBe(0); + expect(fetcher.networkErrorCount).toBe(0); + }); + it("should emit error event on network failure", async () => { server.use( http.get(TEST_URL, () => {