Skip to content

http2: stream.respondWithFile, although capturing stream error when file not found, it also reflects error to req and res in compat layer #14963

Closed
@akc42

Description

@akc42

I'm using the http2.createSecureServer with a request handler which passes request (as req) and response (as res) streams to the handler.

I am using res.stream.respondWithFile()

I am trying to catch errors where the file is not found, so I listen for error event on the stream so my code is like below

      res.stream.on('error', err => {
        if (forwardError || !(err.code === 'ENOENT')) {
          next(err);
        } else {
          //this was probably file not found, in which case we just go to next middleware function.
          next();
        }
      });

      res.stream.respondWithFile(
        filename,
        { 'content-type': map[ext] || 'text/plain',
          'cache-control': 'no-cache' },
        { statCheck });

Even though I am handling the stream error, I am getting the same error reflected again on both req and res variables.

This is fundamentally the following issue with a slight twist (listening to the stream error)
nodejs/http2#168
which was raised before the code landed in node and is is still open

Metadata

Metadata

Assignees

No one assigned

    Labels

    http2Issues or PRs related to the http2 subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions