Skip to content

Commit ab81235

Browse files
taylorklinephryneas
authored andcommitted
Add 'content-type' to ResponseHandler
Closes reduxjs#2354
1 parent 59dfcd2 commit ab81235

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/toolkit/src/query/fetchBaseQuery.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { BaseQueryApi, BaseQueryFn } from './baseQueryTypes'
44
import type { MaybePromise, Override } from './tsHelpers'
55

66
export type ResponseHandler =
7+
| 'content-type'
78
| 'json'
89
| 'text'
910
| ((response: Response) => Promise<any>)
@@ -49,6 +50,10 @@ const handleResponse = async (
4950
return responseHandler(response)
5051
}
5152

53+
if (responseHandler === 'content-type') {
54+
responseHandler = isJsonContentType(response.headers) ? 'json' : 'text'
55+
}
56+
5257
if (responseHandler === 'text') {
5358
return response.text()
5459
}

0 commit comments

Comments
 (0)