reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.63k stars 1.15k forks source link

Redux has problem with decoding `gzip` #4512

Open blooser opened 1 month ago

blooser commented 1 month ago

Hello!

I'm using redux rtk and cofigured it with prepareHeaders. When server throw encoded request with gzip, redux has a problem decoding it and raises TypeError: Decoding failed.

The full error message is:

{
  "status": "PARSING_ERROR",
  "originalStatus": 200,
  "data": "",
  "error": "TypeError: Decoding failed."
}

Prepare header part is:

    baseQuery: fetchBaseQuery({
        baseUrl: `/api`,
        prepareHeaders: (headers) => {
            headers.set('Accept-Encoding', 'gzip');
            return headers;
        },
    }),

I tested encoded response from server and it is correctly encoded, the problem must be on frontend side.

phryneas commented 1 month ago

That's an error that's either thrown either by response.text() or by JSON.parse(text) - assuming you're using the default responseHandler json.

It's an error from your browser. This kind of encoding should be handled by your browser - if it doesn't, your server is probably sending incorrect data.