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

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

Closed
2 tasks done
ikorolev93 opened this issue Nov 27, 2020 · 2 comments · Fixed by #1543
Closed
2 tasks done

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

ikorolev93 opened this issue Nov 27, 2020 · 2 comments · Fixed by #1543
Labels
bug Something does not work as it should ✭ help wanted ✭

Comments

@ikorolev93
Copy link
Contributor

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.
ikorolev93 added a commit to ikorolev93/got that referenced this issue Nov 27, 2020
@ikorolev93 ikorolev93 mentioned this issue Nov 27, 2020
4 tasks
@szmarczak szmarczak added bug Something does not work as it should ✭ help wanted ✭ labels Nov 27, 2020
@akhll
Copy link

akhll commented Jun 10, 2021

why have you closed this issue ?
actually i have the same problem now with got version 11.8.2

const host = 'your_host';
const opts: OptionsOfJSONResponseBody = {
     ...,
     throwHttpErrors: false,
     ...,
}
const res = await got(host, opts).json<ExpectedResponseType>()

Code above throws exception

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)

@szmarczak
Copy link
Collaborator

why have you closed this issue ?

Screenshot_20210610-170920_Chrome

actually i have the same problem now with got version 11.8.2

Please open another issue with the full code to reproduce the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something does not work as it should ✭ help wanted ✭
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants