@@ -36,6 +36,7 @@ const Timer = process.binding('timer_wrap').Timer;
3636const tls_wrap = process . binding ( 'tls_wrap' ) ;
3737const TCP = process . binding ( 'tcp_wrap' ) . TCP ;
3838const Pipe = process . binding ( 'pipe_wrap' ) . Pipe ;
39+ const errors = require ( 'internal/errors' ) ;
3940
4041function onhandshakestart ( ) {
4142 debug ( 'onhandshakestart' ) ;
@@ -59,7 +60,7 @@ function onhandshakestart() {
5960 // state machine and OpenSSL is not re-entrant. We cannot allow the user's
6061 // callback to destroy the connection right now, it would crash and burn.
6162 setImmediate ( function ( ) {
62- var err = new Error ( 'TLS session renegotiation attack detected ' ) ;
63+ var err = new errors . Error ( 'ERR_TLS_SESSION_ATTACK ' ) ;
6364 self . _emitTLSError ( err ) ;
6465 } ) ;
6566 }
@@ -77,14 +78,14 @@ function loadSession(self, hello, cb) {
7778 var once = false ;
7879 function onSession ( err , session ) {
7980 if ( once )
80- return cb ( new Error ( 'TLS session callback was called 2 times ' ) ) ;
81+ return cb ( new errors . Error ( 'ERR_MULTIPLE_CALLBACK ' ) ) ;
8182 once = true ;
8283
8384 if ( err )
8485 return cb ( err ) ;
8586
8687 if ( ! self . _handle )
87- return cb ( new Error ( 'Socket is closed ' ) ) ;
88+ return cb ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
8889
8990 self . _handle . loadSession ( session ) ;
9091 cb ( null ) ;
@@ -106,14 +107,14 @@ function loadSNI(self, servername, cb) {
106107 var once = false ;
107108 self . _SNICallback ( servername , function ( err , context ) {
108109 if ( once )
109- return cb ( new Error ( 'TLS SNI callback was called 2 times ' ) ) ;
110+ return cb ( new errors . Error ( 'ERR_MULTIPLE_CALLBACK ' ) ) ;
110111 once = true ;
111112
112113 if ( err )
113114 return cb ( err ) ;
114115
115116 if ( ! self . _handle )
116- return cb ( new Error ( 'Socket is closed ' ) ) ;
117+ return cb ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
117118
118119 // TODO(indutny): eventually disallow raw `SecureContext`
119120 if ( context )
@@ -152,14 +153,14 @@ function requestOCSP(self, hello, ctx, cb) {
152153 var once = false ;
153154 function onOCSP ( err , response ) {
154155 if ( once )
155- return cb ( new Error ( 'TLS OCSP callback was called 2 times ' ) ) ;
156+ return cb ( new errors . Error ( 'ERR_MULTIPLE_CALLBACK ' ) ) ;
156157 once = true ;
157158
158159 if ( err )
159160 return cb ( err ) ;
160161
161162 if ( ! self . _handle )
162- return cb ( new Error ( 'Socket is closed ' ) ) ;
163+ return cb ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
163164
164165 if ( response )
165166 self . _handle . setOCSPResponse ( response ) ;
@@ -192,7 +193,7 @@ function oncertcb(info) {
192193 return self . destroy ( err ) ;
193194
194195 if ( ! self . _handle )
195- return self . destroy ( new Error ( 'Socket is closed ' ) ) ;
196+ return self . destroy ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
196197
197198 try {
198199 self . _handle . certCbDone ( ) ;
@@ -221,7 +222,7 @@ function onnewsession(key, session) {
221222 once = true ;
222223
223224 if ( ! self . _handle )
224- return self . destroy ( new Error ( 'Socket is closed ' ) ) ;
225+ return self . destroy ( new errors . Error ( 'ERR_SOCKET_CLOSED ' ) ) ;
225226
226227 self . _handle . newSessionDone ( ) ;
227228
@@ -552,7 +553,7 @@ TLSSocket.prototype.renegotiate = function(options, callback) {
552553 }
553554 if ( ! this . _handle . renegotiate ( ) ) {
554555 if ( callback ) {
555- process . nextTick ( callback , new Error ( 'Failed to renegotiate ' ) ) ;
556+ process . nextTick ( callback , new errors . Error ( 'ERR_TLS_RENEGOTIATE ' ) ) ;
556557 }
557558 return false ;
558559 }
@@ -578,7 +579,7 @@ TLSSocket.prototype.getTLSTicket = function getTLSTicket() {
578579} ;
579580
580581TLSSocket . prototype . _handleTimeout = function ( ) {
581- this . _emitTLSError ( new Error ( 'TLS handshake timeout ' ) ) ;
582+ this . _emitTLSError ( new errors . Error ( 'ERR_TLS_HANDSHAKE_TIMEOUT ' ) ) ;
582583} ;
583584
584585TLSSocket . prototype . _emitTLSError = function ( err ) {
@@ -780,7 +781,7 @@ function Server(options, listener) {
780781 } else if ( options == null || typeof options === 'object' ) {
781782 options = options || { } ;
782783 } else {
783- throw new TypeError ( 'options must be an object' ) ;
784+ throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , ' options' , ' object') ;
784785 }
785786
786787
@@ -811,7 +812,7 @@ function Server(options, listener) {
811812 var timeout = options . handshakeTimeout || ( 120 * 1000 ) ;
812813
813814 if ( typeof timeout !== 'number' ) {
814- throw new TypeError ( 'handshakeTimeout must be a number' ) ;
815+ throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'timeout' , ' number') ;
815816 }
816817
817818 if ( self . sessionTimeout ) {
@@ -949,7 +950,7 @@ Server.prototype.setOptions = function(options) {
949950// SNI Contexts High-Level API
950951Server . prototype . addContext = function ( servername , context ) {
951952 if ( ! servername ) {
952- throw new Error ( '"servername" is required parameter for Server.addContext ' ) ;
953+ throw new errors . Error ( 'ERR_TLS_REQUIRED_SERVER_NAME ' ) ;
953954 }
954955
955956 var re = new RegExp ( '^' +
@@ -1088,8 +1089,7 @@ exports.connect = function(...args /* [port,] [host,] [options,] [cb] */) {
10881089 // specified in options.
10891090 var ekeyinfo = socket . getEphemeralKeyInfo ( ) ;
10901091 if ( ekeyinfo . type === 'DH' && ekeyinfo . size < options . minDHSize ) {
1091- var err = new Error ( 'DH parameter size ' + ekeyinfo . size +
1092- ' is less than ' + options . minDHSize ) ;
1092+ var err = new errors . Error ( 'ERR_TLS_DH_PARAM_SIZE' , ekeyinfo . size ) ;
10931093 socket . emit ( 'error' , err ) ;
10941094 socket . destroy ( ) ;
10951095 return ;
0 commit comments