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

Response without body cause an error during deserialization #1

Open
beckelmw opened this issue Feb 26, 2018 · 1 comment
Open

Response without body cause an error during deserialization #1

beckelmw opened this issue Feb 26, 2018 · 1 comment

Comments

@beckelmw
Copy link

We have an API that responds with 201s and 204s which have a null response body. This results in the following error:

TypeError: Failed to construct 'Response': Response with null body status cannot have body
at fetch-robot.js:1363

This is the code:

             function deserializeResponse(response) {
                return response.text().then(function(text) {
                    return new window.Response(text, {
                        status: response.status,
                        statusText: response.statusText,
                        headers: deserializeHeaders(response.headers)
                    });
                });
            }

Should be a simple fix to construct the object and only add the statusText if it is not null.

I tried to fork the project so that I could submit a PR to fix this but could not get it to build or run tests with the dependencies that were installed unfortunately.

@beckelmw
Copy link
Author

This change in serdes.js seems to fix the issue:

export function deserializeResponse(response : SerializedResponseType) : ZalgoPromise<Response> {
    return response.text().then(text => {
        text = text || null; // <--------------------------------------- Added this line
        return new window.Response(text, {
            status:     response.status,
            statusText: response.statusText,
            headers:    deserializeHeaders(response.headers)
        });
    });
}

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

1 participant