Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting a default response handler for fetchBaseQuery #4544

Open
imp-dance opened this issue Aug 5, 2024 · 1 comment
Open

Exporting a default response handler for fetchBaseQuery #4544

imp-dance opened this issue Aug 5, 2024 · 1 comment

Comments

@imp-dance
Copy link
Contributor

imp-dance commented Aug 5, 2024

It seems to me that the default response handler for fetchBaseQuery is "json". As far as I can tell, this is equivalent to parsing the response as text, and then doing JSON.parse on the text after checking its' length. This is not really documented properly anywhere to my knowledge, I figured it out by scanning through the source code.

My original assumption was that the default response handler was async (res) => await res.json()

When implementing a wrapper response handler it's a bit cumbersome and hard to figure out that what I need to actually reimplement to mirror the behavior is this:

responseHandler: async (res) => {
   const text = await res.text();
   return text.length ? JSON.parse(text) : null;
}

I suggest exporting the above function as a defaultResponseHandler, so that wrappers can be easily created as such:

responseHandler: async (res) => {
   // do some stuff
   return await defaultResponseHandler(res);
}
@imp-dance
Copy link
Contributor Author

Opened a PR to just add the default handler directly to the docs. That would also suffice as an alternative as far as I care. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants