summaryrefslogtreecommitdiff
path: root/lib/_http_outgoing.js
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2018-03-04 22:16:24 +0100
committerMichaël Zasso <targos@protonmail.com>2018-03-07 14:54:38 +0100
commit1d2fd8b65bacaf4401450edc8ed529106cbcfc67 (patch)
treedd6230e888c69ef3dc1b19de1ea8f9de7a81fd63 /lib/_http_outgoing.js
parentcb5f9a6d871f6b2e0da8fa72dc2e91fb37ef9713 (diff)
downloadandroid-node-v8-1d2fd8b65bacaf4401450edc8ed529106cbcfc67.tar.gz
android-node-v8-1d2fd8b65bacaf4401450edc8ed529106cbcfc67.tar.bz2
android-node-v8-1d2fd8b65bacaf4401450edc8ed529106cbcfc67.zip
lib: port remaining errors to new system
PR-URL: https://github.com/nodejs/node/pull/19137 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'lib/_http_outgoing.js')
-rw-r--r--lib/_http_outgoing.js49
1 files changed, 28 insertions, 21 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js
index 985b74679c..cd7caae9ae 100644
--- a/lib/_http_outgoing.js
+++ b/lib/_http_outgoing.js
@@ -33,7 +33,17 @@ const checkInvalidHeaderChar = common._checkInvalidHeaderChar;
const { outHeadersKey } = require('internal/http');
const { async_id_symbol } = require('internal/async_hooks').symbols;
const { nextTick } = require('internal/process/next_tick');
-const errors = require('internal/errors');
+const {
+ ERR_HTTP_HEADERS_SENT,
+ ERR_HTTP_INVALID_HEADER_VALUE,
+ ERR_HTTP_TRAILER_INVALID,
+ ERR_INVALID_HTTP_TOKEN,
+ ERR_INVALID_ARG_TYPE,
+ ERR_INVALID_CHAR,
+ ERR_METHOD_NOT_IMPLEMENTED,
+ ERR_STREAM_CANNOT_PIPE,
+ ERR_STREAM_WRITE_AFTER_END
+} = require('internal/errors').codes;
const { CRLF, debug } = common;
const { utcDate } = internalHttp;
@@ -165,7 +175,7 @@ Object.defineProperty(OutgoingMessage.prototype, '_headerNames', {
OutgoingMessage.prototype._renderHeaders = function _renderHeaders() {
if (this._header) {
- throw new errors.Error('ERR_HTTP_HEADERS_SENT', 'render');
+ throw new ERR_HTTP_HEADERS_SENT('render');
}
var headersMap = this[outHeadersKey];
@@ -424,7 +434,7 @@ function _storeHeader(firstLine, headers) {
// header fields, regardless of the header fields present in the
// message, and thus cannot contain a message body or 'trailers'.
if (this.chunkedEncoding !== true && state.trailer) {
- throw new errors.Error('ERR_HTTP_TRAILER_INVALID');
+ throw new ERR_HTTP_TRAILER_INVALID();
}
this._header = state.header + CRLF;
@@ -488,12 +498,12 @@ function matchHeader(self, state, field, value) {
function validateHeader(name, value) {
let err;
if (typeof name !== 'string' || !name || !checkIsHttpToken(name)) {
- err = new errors.TypeError('ERR_INVALID_HTTP_TOKEN', 'Header name', name);
+ err = new ERR_INVALID_HTTP_TOKEN('Header name', name);
} else if (value === undefined) {
- err = new errors.TypeError('ERR_HTTP_INVALID_HEADER_VALUE', value, name);
+ err = new ERR_HTTP_INVALID_HEADER_VALUE(value, name);
} else if (checkInvalidHeaderChar(value)) {
debug('Header "%s" contains invalid characters', name);
- err = new errors.TypeError('ERR_INVALID_CHAR', 'header content', name);
+ err = new ERR_INVALID_CHAR('header content', name);
}
if (err !== undefined) {
Error.captureStackTrace(err, validateHeader);
@@ -503,7 +513,7 @@ function validateHeader(name, value) {
OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
if (this._header) {
- throw new errors.Error('ERR_HTTP_HEADERS_SENT', 'set');
+ throw new ERR_HTTP_HEADERS_SENT('set');
}
validateHeader(name, value);
@@ -529,7 +539,7 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
OutgoingMessage.prototype.getHeader = function getHeader(name) {
if (typeof name !== 'string') {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'name', 'string');
+ throw new ERR_INVALID_ARG_TYPE('name', 'string');
}
if (!this[outHeadersKey]) return;
@@ -565,7 +575,7 @@ OutgoingMessage.prototype.getHeaders = function getHeaders() {
OutgoingMessage.prototype.hasHeader = function hasHeader(name) {
if (typeof name !== 'string') {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'name', 'string');
+ throw new ERR_INVALID_ARG_TYPE('name', 'string');
}
return !!(this[outHeadersKey] && this[outHeadersKey][name.toLowerCase()]);
@@ -574,11 +584,11 @@ OutgoingMessage.prototype.hasHeader = function hasHeader(name) {
OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
if (typeof name !== 'string') {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'name', 'string');
+ throw new ERR_INVALID_ARG_TYPE('name', 'string');
}
if (this._header) {
- throw new errors.Error('ERR_HTTP_HEADERS_SENT', 'remove');
+ throw new ERR_HTTP_HEADERS_SENT('remove');
}
var key = name.toLowerCase();
@@ -605,7 +615,7 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
OutgoingMessage.prototype._implicitHeader = function _implicitHeader() {
- throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', '_implicitHeader()');
+ throw new ERR_METHOD_NOT_IMPLEMENTED('_implicitHeader()');
};
Object.defineProperty(OutgoingMessage.prototype, 'headersSent', {
@@ -622,7 +632,7 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
function write_(msg, chunk, encoding, callback, fromEnd) {
if (msg.finished) {
- const err = new errors.Error('ERR_STREAM_WRITE_AFTER_END');
+ const err = new ERR_STREAM_WRITE_AFTER_END();
nextTick(msg.socket && msg.socket[async_id_symbol],
writeAfterEndNT.bind(msg),
err,
@@ -642,8 +652,7 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
}
if (!fromEnd && typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument',
- ['string', 'Buffer']);
+ throw new ERR_INVALID_ARG_TYPE('first argument', ['string', 'Buffer']);
}
@@ -711,12 +720,11 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
value = headers[key];
}
if (typeof field !== 'string' || !field || !checkIsHttpToken(field)) {
- throw new errors.TypeError('ERR_INVALID_HTTP_TOKEN', 'Trailer name',
- field);
+ throw new ERR_INVALID_HTTP_TOKEN('Trailer name', field);
}
if (checkInvalidHeaderChar(value)) {
debug('Trailer "%s" contains invalid characters', field);
- throw new errors.TypeError('ERR_INVALID_CHAR', 'trailer content', field);
+ throw new ERR_INVALID_CHAR('trailer content', field);
}
this._trailer += field + ': ' + escapeHeaderValue(value) + CRLF;
}
@@ -742,8 +750,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
var uncork;
if (chunk) {
if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
- throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument',
- ['string', 'Buffer']);
+ throw new ERR_INVALID_ARG_TYPE('first argument', ['string', 'Buffer']);
}
if (!this._header) {
if (typeof chunk === 'string')
@@ -874,7 +881,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 errors.Error('ERR_STREAM_CANNOT_PIPE'));
+ this.emit('error', new ERR_STREAM_CANNOT_PIPE());
};
module.exports = {