Skip to content

Exporting a default response handler for fetchBaseQuery #4544

Open
@imp-dance

Description

@imp-dance

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions