Skip to content

Return empty object on 204 No Content... #165

@dandv

Description

@dandv

...instead of throwing a syntax error due to attempting to JSON parse ''.

let fetch = require('node-fetch');
fetch('http://httpbin.org/status/204').then(res => res.json()).then(object => {
    console.log(object);
}).catch(error => console.error(error));

Demo: http://runkit.com/dandv/node-fetch-204-no-content

Fixing this would attain compatibility with request and got.

More generally, it would be more tolerant to return an empty object if the response is the empty string (regardless of the status code being 204 or other 2xx).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions