question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onReq with finalhandler = Error

See original GitHub issue

Why this code is not working?

HttpProxy2.web(req, source.http.res, {
	hostname: domainTarget.target.split("/")[0],
	port: domainTarget.port,

	onRes: function (req: Http2.Http2ServerRequest, res: Http2.Http2ServerResponse, proxyRes: Http.ServerResponse, callback: ()=>any) {
		callback();
	}
}, function (err: Error, req: Http.IncomingMessage | Http2.Http2ServerRequest, res: Http.ServerResponse | Http2.Http2ServerResponse){
	if(err){
		FinalHandler(req, res)(err);
	}
});

Exception:

TypeError: Cannot read property 'Symbol(req)' of undefined
    at onComplete (E:\***\***\node_modules\http2-proxy\index.js:165:18)
    at Object.onRes (E:\***\***\lib\Worker.ts:332:29)
    at ClientRequest.onProxyResponse (E:\***\***\node_modules\http2-proxy\index.js:269:24)
    at ClientRequest.emit (events.js:182:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:546:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
    at Socket.socketOnData (_http_client.js:432:20)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at TCP.onread (net.js:639:20)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Muhaahcommented, Aug 26, 2018

That works, but I think its kind of confusing and ugly for my use case. I only want to set some Headers and with the old version 1.3.2 its easy to accomplish. A function to add Headers to the response would be nice.

By the way: The proxyRes from onRes is not a real Http.ServerResponse | Http2.Http2ServerResponse object … proxyRes.getHeaders() failed.

And thanks for your support and help

1reaction
ronagcommented, Aug 26, 2018

If you want to use it you have to handle the proxyRes => res logic, i.e.

    res.statusCode = proxyRes.statusCode
    for (const [ key, value ] of Object.entries(proxyRes.headers)) {
      res.setHeader(key, value)
    }
    proxyRes.pipe(res)

You only need the callback if you want to finish before the usual life cycle of proxyRes and res.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pillarjs/finalhandler: Node.js final http responder - GitHub
This function is to be invoked as fn(err) . If err is falsy, the handler will write out a 404 response to the...
Read more >
node-http2-proxy - npm
No longer handles ends or destroys response on error. Use an appropriate error handler such as finalhandler .
Read more >
How to fix finalhandler error when running npm install?
I'am trying to create a new Angular project from scratch running following command: ng new porjectName. but I get following error:
Read more >
http2-proxy - UNPKG
35, console.error('proxy error', err). 36, finalhandler(req, res)(err). 37, }. 38, }. 39. 40, const defaultWSHandler = (err, req, socket, head) => {.
Read more >
Http2-proxy - npm.io
Use a final and/or error handler since errored responses won't be cleaned up automatically. This makes it possible to perform retries. const finalhandler...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found