Skip to content

Commit

Permalink
Solves devlucky#159 check content type in fetch response
Browse files Browse the repository at this point in the history
  • Loading branch information
jquintana-atlassian committed Apr 10, 2019
1 parent 676a441 commit 3e1eb65
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/interceptors/fetchInterceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ import { mapRequestInfoToUrlString, canUseWindow } from "../utils";

const nativeFetch = canUseWindow && window.fetch;
const fakeResponse = (response = {}, headers = {}) => {
const responseStr = JSON.stringify(response);
return new Response(responseStr, { headers });
// If content type exist and is different to application/json no parse the response
if (headers['content-type'] && headers['content-type'].indexOf('application/json') == -1) {
return new Response(response, { headers });
}

// Default handler, If no content type response as json.
return new Response(JSON.stringify(response), { headers });
};

export class FakeFetch {
Expand Down

0 comments on commit 3e1eb65

Please sign in to comment.