mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 17:32:22 +00:00

A couple of lib/_http_outgoing.js's errors were still in the "old style": `throw new Error(<some message here>)`. This commit migrates those 2 old style errors to the "new style": internal/errors.js's error-system. In the future, changes to these errors' messages won't break semver-major status. With the old style, changes to these errors' messages broke semver-major status. It was inconvenient. Refs: https://github.com/nodejs/node/issues/17709 PR-URL: https://github.com/nodejs/node/pull/17837 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
37 lines
946 B
JavaScript
37 lines
946 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const http = require('http');
|
|
const stream = require('stream');
|
|
|
|
// Verify that when piping a stream to an `OutgoingMessage` (or a type that
|
|
// inherits from `OutgoingMessage`), if data is emitted after the
|
|
// `OutgoingMessage` was closed - a `write after end` error is raised
|
|
|
|
class MyStream extends stream {}
|
|
|
|
const server = http.createServer(common.mustCall(function(req, res) {
|
|
const myStream = new MyStream();
|
|
myStream.pipe(res);
|
|
|
|
process.nextTick(common.mustCall(() => {
|
|
res.end();
|
|
myStream.emit('data', 'some data');
|
|
res.on('error', common.expectsError({
|
|
code: 'ERR_STREAM_WRITE_AFTER_END',
|
|
type: Error
|
|
}));
|
|
|
|
process.nextTick(common.mustCall(() => server.close()));
|
|
}));
|
|
}));
|
|
|
|
server.listen(0);
|
|
|
|
server.on('listening', common.mustCall(function() {
|
|
http.request({
|
|
port: server.address().port,
|
|
method: 'GET',
|
|
path: '/'
|
|
}).end();
|
|
}));
|