Skip to content

JSON shortcut does not work when using throwHttpErrors: false #1540

@ikorolev93

Description

@ikorolev93

Describe the bug

  • Node.js version: v14.14.0
  • OS & version: Fedora 33

When the server returns an error code with JSON body, and I try to parse it using .json() and {throwHttpErrors: false}, I get the following error:

TypeError: Cannot read property 'request' of undefined
    at /path/to/my/project/node_modules/got/dist/source/as-promise/index.js:157:48
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Actual behavior

TypeError is thrown

Expected behavior

Returning the body of response, parsed as JSON (matching the behavior of {responseType: 'json', resolveOnlyBody: true}, as documented)

Code to reproduce

https://runkit.com/embed/3tt06wxjbio1

const got = require("got");
await got("https://api.github.com/user", {throwHttpErrors: false}).json();

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions