Skip to content

Commit

Permalink
fix fetchBaseQuery for usage with node-fetch (#1473)
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas authored Sep 3, 2021
1 parent e3bc1fe commit c020f97
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/toolkit/src/query/fetchBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,29 @@ export function fetchBaseQuery({

meta.response = responseClone

let resultData
let resultData: any
let responseText: string = ''
try {
resultData = await handleResponse(response, responseHandler)
let handleResponseError
await Promise.all([
handleResponse(response, responseHandler).then(
(r) => (resultData = r),
(e) => (handleResponseError = e)
),
// see https://github.com/node-fetch/node-fetch/issues/665#issuecomment-538995182
// we *have* to "use up" both streams at the same time or they will stop running in node-fetch scenarios
responseClone.text().then(
(r) => (responseText = r),
() => {}
),
])
if (handleResponseError) throw handleResponseError
} catch (e) {
return {
error: {
status: 'PARSING_ERROR',
originalStatus: response.status,
data: await responseClone.clone().text(),
data: responseText,
error: String(e),
},
meta,
Expand Down

0 comments on commit c020f97

Please sign in to comment.