Skip to content

Commit 32509ab

Browse files
authored
Merge pull request #27 from mauchede/fix/validation
Reject only 5XX errors
2 parents a02b839 + 3294408 commit 32509ab

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/hydra/fetchJsonLd.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export default function fetchJsonLd(url, options = {}) {
2222

2323
return fetch(url, options)
2424
.then(response => {
25-
if (204 === response.status) {
25+
const { headers, status } = response;
26+
if (204 === status) {
2627
return Promise.resolve({ response });
2728
}
28-
29-
if (false === response.ok || !response.headers.has('Content-Type') || !response.headers.get('Content-Type').includes(jsonLdMimeType)) {
29+
if (500 <= status || !headers.has('Content-Type') || !headers.get('Content-Type').includes(jsonLdMimeType)) {
3030
return Promise.reject({ response });
3131
}
3232

src/hydra/fetchJsonLd.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ test('fetch an error', () => {
4646
test('fetch an empty document', () => {
4747
fetch.mockResponseOnce('', {status: 204, statusText: 'No Content', headers: new Headers({'Content-Type': 'text/html'})});
4848

49-
return fetchJsonLd('/foo.jsonld').then(({response}) => {
50-
expect(response.ok).toBe(true);
51-
expect(response.body).toBe(undefined);
49+
return fetchJsonLd('/foo.jsonld').then(data => {
50+
expect(data.response.ok).toBe(true);
51+
expect(data.body).toBe(undefined);
5252
});
5353
});

0 commit comments

Comments
 (0)