diff --git a/doc/api/errors.md b/doc/api/errors.md
index 3eb6f921556..a3397eea376 100644
--- a/doc/api/errors.md
+++ b/doc/api/errors.md
@@ -1513,6 +1513,11 @@ a hostname in the first parameter.
An excessive amount of TLS renegotiations is detected, which is a potential
vector for denial-of-service attacks.
+
+### ERR_TLS_RENEGOTIATION_DISABLED
+
+An attempt was made to renegotiate TLS on a socket instance with TLS disabled.
+
### ERR_TRANSFORM_ALREADY_TRANSFORMING
diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js
index e30efa4159b..07d7cb72987 100644
--- a/lib/_tls_wrap.js
+++ b/lib/_tls_wrap.js
@@ -70,8 +70,7 @@ function onhandshakestart() {
}
if (owner[kDisableRenegotiation] && this.handshakes > 0) {
- const err = new Error('TLS session renegotiation disabled for this socket');
- owner._emitTLSError(err);
+ owner._emitTLSError(new errors.Error('ERR_TLS_RENEGOTIATION_DISABLED'));
}
}
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 779343e0664..abb999499cc 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -474,6 +474,8 @@ E('ERR_TLS_CERT_ALTNAME_INVALID',
'Hostname/IP does not match certificate\'s altnames: %s');
E('ERR_TLS_DH_PARAM_SIZE', 'DH parameter size %s is less than 2048');
E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout');
+E('ERR_TLS_RENEGOTIATION_DISABLED',
+ 'TLS session renegotiation disabled for this socket');
E('ERR_TLS_RENEGOTIATION_FAILED', 'Failed to renegotiate');
E('ERR_TLS_REQUIRED_SERVER_NAME',
'"servername" is required parameter for Server.addContext');
diff --git a/test/parallel/test-tls-disable-renegotiation.js b/test/parallel/test-tls-disable-renegotiation.js
index 7e64710da52..b688079a58a 100644
--- a/test/parallel/test-tls-disable-renegotiation.js
+++ b/test/parallel/test-tls-disable-renegotiation.js
@@ -17,9 +17,11 @@ const options = {
const server = tls.Server(options, common.mustCall((socket) => {
socket.on('error', common.mustCall((err) => {
- assert.strictEqual(
- err.message,
- 'TLS session renegotiation disabled for this socket');
+ common.expectsError({
+ type: Error,
+ code: 'ERR_TLS_RENEGOTIATION_DISABLED',
+ message: 'TLS session renegotiation disabled for this socket'
+ })(err);
socket.destroy();
server.close();
}));