diff --git a/packages/toolkit/src/query/fetchBaseQuery.ts b/packages/toolkit/src/query/fetchBaseQuery.ts index 8a555852c4..173f3e1bbc 100644 --- a/packages/toolkit/src/query/fetchBaseQuery.ts +++ b/packages/toolkit/src/query/fetchBaseQuery.ts @@ -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 = | { /** @@ -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() + } }