Skip to content

Commit

Permalink
[fix] content-type check.
Browse files Browse the repository at this point in the history
  • Loading branch information
sagrawal-godaddy committed Oct 9, 2018
1 parent 00c35f7 commit ead3029
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/fetchUtils.js
Expand Up @@ -24,12 +24,13 @@ handlers.decode = function (response) {
if (contentType.includes('application/json')) {
return response.json()
.then(data => handlers.finish(response, data));
} else if (contentType.includes('text/html') || contentType.includes('text/plain')) {
}
try {
return response.text()
.then(data => handlers.finish(response, data));
} catch (err) {
return Promise.reject(`Content-type ${contentType} not supported`);
}

return Promise.reject(`Content-type ${contentType} not supported`);
};

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/fetchUtils.spec.js
Expand Up @@ -138,6 +138,9 @@ describe('fetchUtils', () => {
});

it('rejects for unhandled content types', (done) => {
mockResponse.text = jest.fn().mockImplementation(() => {
throw new Error('`text` not implemented');
});
mockResponse.headers.set('content-type', 'some/type');
handlers.decode(mockResponse).catch(data => {
expect(data).toContain('not supported');
Expand Down

0 comments on commit ead3029

Please sign in to comment.