diff --git a/lib/documentLoaders/xhr.js b/lib/documentLoaders/xhr.js index 8674cfb6..3db04bfe 100644 --- a/lib/documentLoaders/xhr.js +++ b/lib/documentLoaders/xhr.js @@ -89,8 +89,8 @@ module.exports = ({ // handle Link Header (avoid unsafe header warning by existence testing) let linkHeader; - if(REGEX_LINK_HEADER.test(req.getAllResponseHeaders()) && - contentType !== 'application/ld+json') { + if(contentType !== 'application/ld+json' && + REGEX_LINK_HEADER.test(req.getAllResponseHeaders())) { linkHeader = req.getResponseHeader('Link'); } if(linkHeader && contentType !== 'application/ld+json') { diff --git a/lib/jsonld.js b/lib/jsonld.js index 1e9aa78a..00509b70 100644 --- a/lib/jsonld.js +++ b/lib/jsonld.js @@ -935,16 +935,17 @@ jsonld.get = async function(url, options) { } } catch(e) { if(e.name === 'jsonld.InvalidScriptElement') { + // pass error detected in HTML decode throw (e); - } else { - throw new JsonLdError( - 'Could not retrieve a JSON-LD document from the URL.', - 'jsonld.LoadDocumentError', { - code: 'loading document failed', - cause: e, - remoteDoc - }); } + // otherwise, general loading error + throw new JsonLdError( + 'Could not retrieve a JSON-LD document from the URL.', + 'jsonld.LoadDocumentError', { + code: 'loading document failed', + cause: e, + remoteDoc + }); } return remoteDoc;