Sitelet https://github.com/nodejs/help/issues/507
Skip to content

Is it necessary to listen for the "error" event in a http.request response? #507

Description

@zbjornson
  • Node.js Version: 6+
  • OS: Any
  • Scope (install, code, runtime, meta, other?): runtime
  • Module (and version) (if relevant): http

In the example given for http.request on the http doc page, there's no error event listener on the response. Is there any scenario in which an error would be emitted on the response?

var req = http.request(options, (res) => {
  res.on('data', (chunk) => { /* ... */ });
  res.on('end', () => { /* ... */ });
  res.on('error', () => { /* Can this ever happen? */ });
});

req.on('error', /* (can definitely happen) */);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions