@@ -1127,13 +1127,24 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
1127
1127
}
1128
1128
} ) ( ) . catch ( reject )
1129
1129
) . catch ( ( e : ErrorLike ) => {
1130
- if ( ! e . code && e . message === 'unsupported' && e . stack ?. includes ( 'node:internal/tls/secure-context' ) ) {
1131
- // When something totally unsupported by OpenSSL is used, we get their weird and useless
1132
- // error - without codes or anything. We reformat it here mildly to make that at least
1133
- // a tiny bit clearer.
1134
- e . code = 'ERR_TLS_CONTEXT_UNSUPPORTED' ;
1135
- e . message = "Unsupported TLS configuration" ;
1136
- clientRes . tags . push ( 'passthrough-tls-error:context-unsupported' ) ;
1130
+ if ( ! e . code && e . stack ?. split ( '\n' ) [ 1 ] ?. includes ( 'node:internal/tls/secure-context' ) ) {
1131
+ // OpenSSL can throw all sorts of weird & wonderful errors here, and rarely exposes a
1132
+ // useful error code from them. To handle that, we try to detect the most common cases,
1133
+ // notable including the useless but common 'unsupported' error that covers all
1134
+ // OpenSSL-unsupported (e.g. legacy) configurations.
1135
+
1136
+ let tlsErrorTag : string ;
1137
+ if ( e . message === 'unsupported' ) {
1138
+ e . code = 'ERR_TLS_CONTEXT_UNSUPPORTED' ;
1139
+ tlsErrorTag = 'context-unsupported' ;
1140
+ e . message = 'Unsupported TLS configuration' ;
1141
+ } else {
1142
+ e . code = 'ERR_TLS_CONTEXT_UNKNOWN' ;
1143
+ tlsErrorTag = 'context-unknown' ;
1144
+ e . message = `TLS context error: ${ e . message } ` ;
1145
+ }
1146
+
1147
+ clientRes . tags . push ( `passthrough-tls-error:${ tlsErrorTag } ` ) ;
1137
1148
}
1138
1149
1139
1150
// All errors anywhere above (thrown or from explicit reject()) should end up here.
0 commit comments