From 3294408bac83adb94f29b5d7d1496dddb710c4d5 Mon Sep 17 00:00:00 2001 From: Morgan Auchede Date: Wed, 10 Jan 2018 15:34:58 +0100 Subject: [PATCH] Reject only 5XX errors. --- src/hydra/fetchJsonLd.js | 6 +++--- src/hydra/fetchJsonLd.test.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hydra/fetchJsonLd.js b/src/hydra/fetchJsonLd.js index 5c992da..5aaff41 100644 --- a/src/hydra/fetchJsonLd.js +++ b/src/hydra/fetchJsonLd.js @@ -22,11 +22,11 @@ export default function fetchJsonLd(url, options = {}) { return fetch(url, options) .then(response => { - if (204 === response.status) { + const { headers, status } = response; + if (204 === status) { return Promise.resolve({ response }); } - - if (false === response.ok || !response.headers.has('Content-Type') || !response.headers.get('Content-Type').includes(jsonLdMimeType)) { + if (500 <= status || !headers.has('Content-Type') || !headers.get('Content-Type').includes(jsonLdMimeType)) { return Promise.reject({ response }); } diff --git a/src/hydra/fetchJsonLd.test.js b/src/hydra/fetchJsonLd.test.js index bcccd20..d0ecfae 100644 --- a/src/hydra/fetchJsonLd.test.js +++ b/src/hydra/fetchJsonLd.test.js @@ -46,8 +46,8 @@ test('fetch an error', () => { test('fetch an empty document', () => { fetch.mockResponseOnce('', {status: 204, statusText: 'No Content', headers: new Headers({'Content-Type': 'text/html'})}); - return fetchJsonLd('/foo.jsonld').then(({response}) => { - expect(response.ok).toBe(true); - expect(response.body).toBe(undefined); + return fetchJsonLd('/foo.jsonld').then(data => { + expect(data.response.ok).toBe(true); + expect(data.body).toBe(undefined); }); });