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

The responseHandler should respect Content-Type headers #2354

Closed
taylorkline opened this issue May 25, 2022 · 3 comments · Fixed by #2363
Closed

The responseHandler should respect Content-Type headers #2354

taylorkline opened this issue May 25, 2022 · 3 comments · Fixed by #2363
Milestone

Comments

@taylorkline
Copy link
Contributor

taylorkline commented May 25, 2022

Howdy!

I believe the default responseHandler should be a little more intelligent to handle the response based on the content type header.

For example, in the default Go http package, you can see it is typical to return a response body of "404 page not found", "Unauthorized," etc. with non-200 responses.

It seems very counterintuitive that one must define a custom responseHandler for each and every endpoint to avoid RTK Query failing with PARSING_ERROR in some rather common use-cases.

taylorkline added a commit to taylorkline/redux-toolkit that referenced this issue May 27, 2022
phryneas pushed a commit to taylorkline/redux-toolkit that referenced this issue Jul 8, 2022
@markerikson markerikson added this to the 1.9 milestone Oct 26, 2022
@markerikson
Copy link
Collaborator

Oh hey this has been long merged and will be in 1.9.

@taylorkline taylorkline changed the title The default responseHandler should respect Content-Type headers The responseHandler should respect Content-Type headers Oct 26, 2022
@taylorkline
Copy link
Contributor Author

@markerikson I changed the title, as there is now an option to respect Content-Type headers, but it is not the default.

@henkkasoft
Copy link

Thanks for solving this problem.
If you want to respect Content-Type for every endpoint, you can give responseHandler as parameter for fetchBaseQuery.

  baseQuery: fetchBaseQuery({
    baseUrl: '/my-api',
    responseHandler: 'content-type',
    ...
  }),

#2440 (comment)

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

Successfully merging a pull request may close this issue.

3 participants