From 0d7ed717c388a6ebdabb4fe2a9c5ab0ef50d2f1c Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Thu, 24 Aug 2023 16:32:50 +0300 Subject: [PATCH] Fixed 304 handling for bimi --- lib/bimi-handler.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/bimi-handler.js b/lib/bimi-handler.js index 5b229b2b..b40a3ecc 100644 --- a/lib/bimi-handler.js +++ b/lib/bimi-handler.js @@ -77,6 +77,13 @@ class BimiHandler { dispatcher: fetchAgent }); + if (res.status === 304) { + // no changes + let err = new Error('No changes'); + err.code = 'NO_CHANGES'; + throw err; + } + if (!res.ok) { let error = new Error(`Request failed with status ${res.status}`); error.code = 'HTTP_REQUEST_FAILED'; @@ -106,20 +113,13 @@ class BimiHandler { _bimi_url: url, _bimi_type: bimiType, _bimi_domain: bimiDomain, - _status_code: res?.status, + _status_code: res.status, _req_etag: bimiDocument.etag, _req_last_modified: bimiDocument.lastModified, - _res_etag: res?.headers?.get('ETag'), - _res_last_modified: res?.headers?.get('Last-Modified') + _res_etag: res.headers.get('ETag'), + _res_last_modified: res.headers.get('Last-Modified') }); - if (res?.status === 304) { - // no changes - let err = new Error('No changes'); - err.code = 'NO_CHANGES'; - throw err; - } - if (!res.status || res.status < 200 || res.status >= 300) { let err = new Error(`Invalid response code ${res.status || '-'}`);