Fixed 304 handling for bimi

This commit is contained in:
Andris Reinman 2023-08-24 16:32:50 +03:00
parent e4a2ded7ea
commit 0d7ed717c3
No known key found for this signature in database
GPG key ID: DC6C83F4D584D364

View file

@ -77,6 +77,13 @@ class BimiHandler {
dispatcher: fetchAgent dispatcher: fetchAgent
}); });
if (res.status === 304) {
// no changes
let err = new Error('No changes');
err.code = 'NO_CHANGES';
throw err;
}
if (!res.ok) { if (!res.ok) {
let error = new Error(`Request failed with status ${res.status}`); let error = new Error(`Request failed with status ${res.status}`);
error.code = 'HTTP_REQUEST_FAILED'; error.code = 'HTTP_REQUEST_FAILED';
@ -106,20 +113,13 @@ class BimiHandler {
_bimi_url: url, _bimi_url: url,
_bimi_type: bimiType, _bimi_type: bimiType,
_bimi_domain: bimiDomain, _bimi_domain: bimiDomain,
_status_code: res?.status, _status_code: res.status,
_req_etag: bimiDocument.etag, _req_etag: bimiDocument.etag,
_req_last_modified: bimiDocument.lastModified, _req_last_modified: bimiDocument.lastModified,
_res_etag: res?.headers?.get('ETag'), _res_etag: res.headers.get('ETag'),
_res_last_modified: res?.headers?.get('Last-Modified') _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) { if (!res.status || res.status < 200 || res.status >= 300) {
let err = new Error(`Invalid response code ${res.status || '-'}`); let err = new Error(`Invalid response code ${res.status || '-'}`);