Skip to content

Commit

Permalink
move handleResponse function into scope of fetchBaseQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Jul 8, 2022
1 parent 53befa6 commit beec324
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions packages/toolkit/src/query/fetchBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,6 @@ const defaultValidateStatus = (response: Response) =>
const defaultIsJsonContentType = (headers: Headers) =>
/*applicat*/ /ion\/(vnd\.api\+)?json/.test(headers.get('content-type') || '')

const handleResponse = async (
response: Response,
responseHandler: ResponseHandler
) => {
if (typeof responseHandler === 'function') {
return responseHandler(response)
}

if (responseHandler === 'content-type') {
responseHandler = isJsonContentType(response.headers) ? 'json' : 'text'
}

if (responseHandler === 'json') {
const text = await response.text()
return text.length ? JSON.parse(text) : null
}

return response.text()
}

export type FetchBaseQueryError =
| {
/**
Expand Down Expand Up @@ -345,4 +325,24 @@ export function fetchBaseQuery({
meta,
}
}

async function handleResponse(
response: Response,
responseHandler: ResponseHandler
) {
if (typeof responseHandler === 'function') {
return responseHandler(response)
}

if (responseHandler === 'content-type') {
responseHandler = isJsonContentType(response.headers) ? 'json' : 'text'
}

if (responseHandler === 'json') {
const text = await response.text()
return text.length ? JSON.parse(text) : null
}

return response.text()
}
}

0 comments on commit beec324

Please sign in to comment.