Skip to content

Commit

Permalink
fetchJSON: clone response when reading the body stream not to lock it
Browse files Browse the repository at this point in the history
  • Loading branch information
vlki committed Aug 4, 2020
1 parent bc204df commit 18d023f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/fetchJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const fetchJSON = (url: string | Request | URL, options: Object = {}) => {
const getResponseBody = (response: Response): Promise<ResponseBody> => {
const contentType = response.headers.get('content-type')
return contentType && contentType.indexOf('json') >= 0
? response.text().then(tryParseJSON)
: response.text()
? response.clone().text().then(tryParseJSON)
: response.clone().text()
}

const tryParseJSON = (json: string): Object | null => {
Expand Down

0 comments on commit 18d023f

Please sign in to comment.