Skip to content

Commit bc0bf0f

Browse files
authored
Merge pull request #4545 from imp-dance/patch-1
docs: Added section describing the default response handler for fetch…
2 parents 297b5a7 + af16c4a commit bc0bf0f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/rtk-query/api/fetchBaseQuery.mdx

+11
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@ export const customApi = createApi({
297297
If you make a `json` request to an API that only returns a `200` with an undefined body, `fetchBaseQuery` will pass that through as `undefined` and will not try to parse it as `json`. This can be common with some APIs, especially on `delete` requests.
298298
:::
299299

300+
#### Default response handler
301+
302+
The default response handler is `"json"`, which is equivalent to the following function:
303+
304+
```ts title="Default responseHandler"
305+
const defaultResponseHandler = async (res: Response) => {
306+
const text = await res.text();
307+
return text.length ? JSON.parse(text) : null;
308+
}
309+
```
310+
300311
### Handling non-standard Response status codes
301312

302313
By default, `fetchBaseQuery` will `reject` any `Response` that does not have a status code of `2xx` and set it to `error`. This is the same behavior you've most likely experienced with `axios` and other popular libraries. In the event that you have a non-standard API you're dealing with, you can use the `validateStatus` option to customize this behavior.

0 commit comments

Comments
 (0)