Replies: 0 comments 1 reply
-
Basically you would need to add a listener to the const http = require('node:http');
const server = http.createServer((req, res) => {
const responseStream = yourFileProcessingPipeline(); // Your file processing pipeline here
// Listen for premature close event on the response
req.on('close', () => {
// Abort the responseStream when the premature close occurs
responseStream.destroy(new Error('Premature close occurred'));
});
responseStream.on('error', (err) => {
if (err.code === 'ERR_HTTP_HEADERS_SENT') {
// Handle ERR_HTTP_HEADERS_SENT error here
console.error('Headers already sent:', err.message);
} else {
// Handle other errors that occurred during the response pipeline
console.error('An error occurred:', err.message);
}
});
responseStream.pipe(res); // Pipe the response stream to the HTTP response
});
server.listen(8080, () => {
console.log('Server is running on port 8080');
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Version
16.15
Problematic
I have a server that exposes an endpoint that responds with a file through a
pipeline
. Cancelling the request results in anERR_STREAM_PREMATURE_CLOSE
.When that error occurs, an
ERR_HTTP_HEADERS_SENT
is thrown but I am not able to catch it.I have tried catching it by listening to
process.on('uncaughtException')
andrequest.on('error')
but both options don't work.Any suggestions or ideas about the problem?
Beta Was this translation helpful? Give feedback.
All reactions