Skip to content

got.stream is not pipable on error #1898

Open
@dangkyokhoang

Description

@dangkyokhoang

Describe the bug

  • Node.js version: 15.11.0
  • got version: 11.8.2
  • OS & version: Windows

Actual behavior

response.rawBody <Buffer ...>

On error, got.stream response is not pipable. The response body is under response.rawBody which is supposed to be "only accessible when using Promise API" (https://github.com/sindresorhus/got/blob/main/documentation/3-streams.md#rawbody). I would assume there's no data event as the response body has already been consumed?

Expected behavior

on data <Buffer ...>

Code to reproduce

const got = require('got')

const url = 'https://run.mocky.io/v3/99fc1661-4a34-4334-a123-ae9c02b33db4'

got.stream(url)
  .on('error', error => {
    const { response } = error

    console.log('response.rawBody', response.rawBody)
  })
  .on('data', chunk => {
    console.log('on data', chunk)
  })

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

    questionThe issue is a question about Got

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions