diff options
-rw-r--r-- | lib/_http_outgoing.js | 4 | ||||
-rw-r--r-- | test/parallel/test-http-res-write-after-end.js | 5 | ||||
-rw-r--r-- | test/parallel/test-http-server-write-after-end.js | 6 | ||||
-rw-r--r-- | test/parallel/test-outgoing-message-pipe.js | 13 | ||||
-rw-r--r-- | test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js | 6 |
5 files changed, 18 insertions, 16 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 07cf84866f..324373f385 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -629,7 +629,7 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) { function write_(msg, chunk, encoding, callback, fromEnd) { if (msg.finished) { - var err = new Error('write after end'); + const err = new errors.Error('ERR_STREAM_WRITE_AFTER_END'); nextTick(msg.socket && msg.socket[async_id_symbol], writeAfterEndNT.bind(msg), err, @@ -880,7 +880,7 @@ OutgoingMessage.prototype.flush = internalUtil.deprecate(function() { OutgoingMessage.prototype.pipe = function pipe() { // OutgoingMessage should be write-only. Piping from it is disabled. - this.emit('error', new Error('Cannot pipe, not readable')); + this.emit('error', new errors.Error('ERR_STREAM_CANNOT_PIPE')); }; module.exports = { diff --git a/test/parallel/test-http-res-write-after-end.js b/test/parallel/test-http-res-write-after-end.js index 32c6cf2e08..1d34cf6dcb 100644 --- a/test/parallel/test-http-res-write-after-end.js +++ b/test/parallel/test-http-res-write-after-end.js @@ -25,8 +25,9 @@ const assert = require('assert'); const http = require('http'); const server = http.Server(common.mustCall(function(req, res) { - res.on('error', common.mustCall(function onResError(err) { - assert.strictEqual(err.message, 'write after end'); + res.on('error', common.expectsError({ + code: 'ERR_STREAM_WRITE_AFTER_END', + type: Error })); res.write('This should write.'); diff --git a/test/parallel/test-http-server-write-after-end.js b/test/parallel/test-http-server-write-after-end.js index 045cdcf4b7..a405844cfc 100644 --- a/test/parallel/test-http-server-write-after-end.js +++ b/test/parallel/test-http-server-write-after-end.js @@ -2,7 +2,6 @@ const common = require('../common'); const http = require('http'); -const assert = require('assert'); // Fix for https://github.com/nodejs/node/issues/14368 @@ -10,7 +9,10 @@ const server = http.createServer(handle); function handle(req, res) { res.on('error', common.mustCall((err) => { - assert.strictEqual(err.message, 'write after end'); + common.expectsError({ + code: 'ERR_STREAM_WRITE_AFTER_END', + type: Error + })(err); server.close(); })); diff --git a/test/parallel/test-outgoing-message-pipe.js b/test/parallel/test-outgoing-message-pipe.js index 2030d8f43b..7cfe3687ec 100644 --- a/test/parallel/test-outgoing-message-pipe.js +++ b/test/parallel/test-outgoing-message-pipe.js @@ -1,15 +1,14 @@ 'use strict'; -const assert = require('assert'); const common = require('../common'); const OutgoingMessage = require('_http_outgoing').OutgoingMessage; // Verify that an error is thrown upon a call to `OutgoingMessage.pipe`. const outgoingMessage = new OutgoingMessage(); -assert.throws( - common.mustCall(() => { outgoingMessage.pipe(outgoingMessage); }), - (err) => { - return ((err instanceof Error) && /Cannot pipe, not readable/.test(err)); - }, - 'OutgoingMessage.pipe should throw an error' +common.expectsError( + () => { outgoingMessage.pipe(outgoingMessage); }, + { + code: 'ERR_STREAM_CANNOT_PIPE', + type: Error + } ); diff --git a/test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js b/test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js index 0bd823908a..c6191a906b 100644 --- a/test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js +++ b/test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js @@ -1,7 +1,6 @@ 'use strict'; const common = require('../common'); const http = require('http'); -const assert = require('assert'); const stream = require('stream'); // Verify that when piping a stream to an `OutgoingMessage` (or a type that @@ -17,8 +16,9 @@ const server = http.createServer(common.mustCall(function(req, res) { process.nextTick(common.mustCall(() => { res.end(); myStream.emit('data', 'some data'); - res.on('error', common.mustCall(function(err) { - assert.strictEqual(err.message, 'write after end'); + res.on('error', common.expectsError({ + code: 'ERR_STREAM_WRITE_AFTER_END', + type: Error })); process.nextTick(common.mustCall(() => server.close())); |