@@ -79,7 +79,8 @@ import {
79
79
shouldUseStrictHttps ,
80
80
getClientRelativeHostname ,
81
81
getDnsLookupFunction ,
82
- getTrustedCAs
82
+ getTrustedCAs ,
83
+ buildUpstreamErrorTags
83
84
} from '../passthrough-handling' ;
84
85
85
86
import {
@@ -1123,6 +1124,7 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
1123
1124
1124
1125
options . emitEventCallback ( 'passthrough-abort' , {
1125
1126
downstreamAborted : ! ! ( serverReq ?. aborted ) ,
1127
+ tags : buildUpstreamErrorTags ( e ) ,
1126
1128
error : {
1127
1129
name : e . name ,
1128
1130
code : e . code ,
@@ -1180,37 +1182,7 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
1180
1182
}
1181
1183
} ) ( ) . catch ( reject )
1182
1184
) . catch ( ( e : ErrorLike ) => {
1183
- if ( ! e . code && e . stack ?. split ( '\n' ) [ 1 ] ?. includes ( 'node:internal/tls/secure-context' ) ) {
1184
- // OpenSSL can throw all sorts of weird & wonderful errors here, and rarely exposes a
1185
- // useful error code from them. To handle that, we try to detect the most common cases,
1186
- // notable including the useless but common 'unsupported' error that covers all
1187
- // OpenSSL-unsupported (e.g. legacy) configurations.
1188
-
1189
- let tlsErrorTag : string ;
1190
- if ( e . message === 'unsupported' ) {
1191
- e . code = 'ERR_TLS_CONTEXT_UNSUPPORTED' ;
1192
- tlsErrorTag = 'context-unsupported' ;
1193
- e . message = 'Unsupported TLS configuration' ;
1194
- } else {
1195
- e . code = 'ERR_TLS_CONTEXT_UNKNOWN' ;
1196
- tlsErrorTag = 'context-unknown' ;
1197
- e . message = `TLS context error: ${ e . message } ` ;
1198
- }
1199
-
1200
- clientRes . tags . push ( `passthrough-tls-error:${ tlsErrorTag } ` ) ;
1201
- }
1202
-
1203
- // All errors anywhere above (thrown or from explicit reject()) should end up here.
1204
-
1205
- // We tag the response with the error code, for debugging from events:
1206
- clientRes . tags . push ( 'passthrough-error:' + e . code ) ;
1207
-
1208
- // Tag responses, so programmatic examination can react to this
1209
- // event, without having to parse response data or similar.
1210
- const tlsAlertMatch = / S S L a l e r t n u m b e r ( \d + ) / . exec ( e . message ?? '' ) ;
1211
- if ( tlsAlertMatch ) {
1212
- clientRes . tags . push ( 'passthrough-tls-error:ssl-alert-' + tlsAlertMatch [ 1 ] ) ;
1213
- }
1185
+ clientRes . tags . push ( ...buildUpstreamErrorTags ( e ) ) ;
1214
1186
1215
1187
if ( ( e as any ) . causedByUpstreamError && ! serverReq ?. aborted ) {
1216
1188
if ( e . code === 'ECONNRESET' || e . code === 'ECONNREFUSED' || this . simulateConnectionErrors ) {
0 commit comments