Skip to content

Commit 4bbab59

Browse files
committed
Expose all sorts of other unclear codeless OpenSSL errors
1 parent 0867f72 commit 4bbab59

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/rules/requests/request-handlers.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,13 +1127,24 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
11271127
}
11281128
})().catch(reject)
11291129
).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}`);
11371148
}
11381149

11391150
// All errors anywhere above (thrown or from explicit reject()) should end up here.

0 commit comments

Comments
 (0)