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

Allow setting the default responseHandler at a higher level #2385

Closed
taylorkline opened this issue Jun 4, 2022 · 7 comments
Closed

Allow setting the default responseHandler at a higher level #2385

taylorkline opened this issue Jun 4, 2022 · 7 comments
Milestone

Comments

@taylorkline
Copy link
Contributor

Because of #2354 (which is addressed in #2363, pending feedback), we have resorted to adding a custom responseHandler to each and every endpoint definition.

This gets tedious, and it's easy for one of the several developers on our team to miss a case until we run into a run-time PARSING_ERROR when we get a "text/plain" response.

It would be very convenient to be able to set the default responseHandler across all endpoints in the options to createApi.

@phryneas
Copy link
Member

phryneas commented Jun 5, 2022

A PR adding responseHandler to the FetchBaseQueryArgs argument to fetchBaseQuery would be welcome.

If you are not using TypeScript, it is probably even already possible to pass it into fetchBaseQuery directly at creation.

@markerikson
Copy link
Collaborator

Slightly confused re-reading this, but I think this is fixed by #2363 ?

@markerikson markerikson added this to the 1.9 milestone Oct 26, 2022
@markerikson
Copy link
Collaborator

I take it back. Re-re-reading our own types: I think you can pass responseHandler as part of an individual query object, but not to fetchBaseQuery?

@taylorkline
Copy link
Contributor Author

Short version: it would be nice to be able to specify responseHandler in createApi:

export const pokemonApi = createApi({
  reducerPath: 'pokemonApi',
  baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
  responseHandler: 'content-type',
  endpoints: (builder) => ({
    getPokemonByName: builder.query<Pokemon, string>({
      query: (name) => `pokemon/${name}`,
    }),
  }),
})

Or similar.

@phryneas
Copy link
Member

phryneas commented Oct 26, 2022

I added a PR for that today - #2823

But it's part of fetchBaseQuery. createApi doesn't have any concept of response handlers.

@markerikson
Copy link
Collaborator

Merged into the 1.9 branch

@taylorkline
Copy link
Contributor Author

I can confirm, as per #3136, (and perhaps fixed by #3137), this is not working in 1.9.3.

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

No branches or pull requests

3 participants