Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Using got.post with both body and cache options causes an exception #1021

Closed
2 tasks done
coreyfarrell opened this issue Jan 15, 2020 · 0 comments · Fixed by #1051
Closed
2 tasks done

Using got.post with both body and cache options causes an exception #1021

coreyfarrell opened this issue Jan 15, 2020 · 0 comments · Fixed by #1051
Labels
bug Something does not work as it should ✭ help wanted ✭ regression Something does not work anymore

Comments

@coreyfarrell
Copy link

Describe the bug

Using got.post with both body and cache options causes an exception.

  • Node.js version: 13.6.0
  • OS & version: Fedora 30
  • got version: 10.2.2

Actual behavior

GotError: Cannot read property 'on' of undefined
    at onError (/usr/src/npm/failures/got-test/node_modules/got/dist/source/request-as-event-emitter.js:137:29)
    at EventEmitter.handleRequest (/usr/src/npm/failures/got-test/node_modules/got/dist/source/request-as-event-emitter.js:170:17)
    at destroyer (internal/streams/pipeline.js:27:10)
    at internal/streams/pipeline.js:79:12
    at Array.map (<anonymous>)
    at pipeline (internal/streams/pipeline.js:76:28)
    at internal/util.js:297:30
    at new Promise (<anonymous>)
    at pipeline (internal/util.js:296:12)
    at EventEmitter.handleRequest (/usr/src/npm/failures/got-test/node_modules/got/dist/source/request-as-event-emitter.js:162:23)
    at Object.onceWrapper (events.js:428:26)
    at EventEmitter.emit (events.js:321:20) {
  name: 'RequestError'
}

Expected behavior

No exception. Unsure if options.cache should do anything in this case or be ignored. For my own use that does not matter as the server I'm really working with never provides cachable responses to POST requests. Really the goal for me is to be able to use a shared "base options" object and not have to censor the cache option when performing posts.

Code to reproduce

#!/usr/bin/env node
'use strict';
const got = require('got');

async function main() {
	await got.post('https://httpbin.org/post', {
		body: '',
		cache: new Map()
	});
}

main().catch(error => {
	console.error(error);
	process.exit(1);
});

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@sindresorhus sindresorhus added the bug Something does not work as it should label Jan 15, 2020
@szmarczak szmarczak mentioned this issue Feb 6, 2020
18 tasks
@szmarczak szmarczak added regression Something does not work anymore ✭ help wanted ✭ labels Feb 8, 2020
szmarczak added a commit to szmarczak/got that referenced this issue Feb 29, 2020
szmarczak added a commit to szmarczak/got that referenced this issue Mar 3, 2020
szmarczak added a commit to szmarczak/got that referenced this issue Mar 4, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something does not work as it should ✭ help wanted ✭ regression Something does not work anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants