From eb8e30bee3fe0771bb8d19444c0792b3a61d8bec Mon Sep 17 00:00:00 2001 From: uzlopak Date: Fri, 16 Aug 2024 18:47:02 +0200 Subject: [PATCH 1/3] fix: instantiation of SecureProxyConnectionError should pass options to parent class --- lib/core/errors.js | 8 ++++---- test/proxy-agent.js | 4 +++- types/errors.d.ts | 5 +++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/core/errors.js b/lib/core/errors.js index 9257875c1c3..7a68cf813a5 100644 --- a/lib/core/errors.js +++ b/lib/core/errors.js @@ -1,8 +1,8 @@ 'use strict' class UndiciError extends Error { - constructor (message) { - super(message) + constructor (message, options) { + super(message, options) this.name = 'UndiciError' this.code = 'UND_ERR' } @@ -208,8 +208,8 @@ class ResponseError extends UndiciError { } class SecureProxyConnectionError extends UndiciError { - constructor (cause, message, options) { - super(message, { cause, ...(options ?? {}) }) + constructor (cause, message, options = {}) { + super(message, { cause, ...options }) this.name = 'SecureProxyConnectionError' this.message = message || 'Secure Proxy Connection failed' this.code = 'UND_ERR_PRX_TLS' diff --git a/test/proxy-agent.js b/test/proxy-agent.js index 44451d7a618..6dcdfee450c 100644 --- a/test/proxy-agent.js +++ b/test/proxy-agent.js @@ -794,7 +794,7 @@ test('Proxy via HTTP to HTTP endpoint', async (t) => { }) test('Proxy via HTTPS to HTTP fails on wrong SNI', async (t) => { - t = tspl(t, { plan: 2 }) + t = tspl(t, { plan: 3 }) const server = await buildServer() const proxy = await buildSSLProxy() @@ -832,8 +832,10 @@ test('Proxy via HTTPS to HTTP fails on wrong SNI', async (t) => { try { await request(serverUrl, { dispatcher: proxyAgent }) + throw new Error('should fail') } catch (e) { t.ok(e instanceof SecureProxyConnectionError) + t.ok(e.cause instanceof Error) t.ok(e.cause.code === 'ERR_TLS_CERT_ALTNAME_INVALID') } diff --git a/types/errors.d.ts b/types/errors.d.ts index f6fb73b5a90..c78275c513a 100644 --- a/types/errors.d.ts +++ b/types/errors.d.ts @@ -143,6 +143,11 @@ declare namespace Errors { } export class SecureProxyConnectionError extends UndiciError { + constructor ( + cause: Error, + message?: string, + options?: ErrorOptions + ); name: 'SecureProxyConnectionError'; code: 'UND_ERR_PRX_TLS'; } From cdb7127c01550ece41966a4ada1c5d8901e275ae Mon Sep 17 00:00:00 2001 From: uzlopak Date: Fri, 16 Aug 2024 18:57:22 +0200 Subject: [PATCH 2/3] fix typescript error by making cause optional --- types/errors.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/errors.d.ts b/types/errors.d.ts index c78275c513a..186e0888bee 100644 --- a/types/errors.d.ts +++ b/types/errors.d.ts @@ -144,7 +144,7 @@ declare namespace Errors { export class SecureProxyConnectionError extends UndiciError { constructor ( - cause: Error, + cause?: Error, message?: string, options?: ErrorOptions ); From c913b2e997428186e9c9f51118f4ae42f66339e8 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Fri, 16 Aug 2024 22:03:28 +0200 Subject: [PATCH 3/3] fix ts error --- types/errors.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/errors.d.ts b/types/errors.d.ts index 186e0888bee..a23ed5558b3 100644 --- a/types/errors.d.ts +++ b/types/errors.d.ts @@ -146,7 +146,7 @@ declare namespace Errors { constructor ( cause?: Error, message?: string, - options?: ErrorOptions + options?: Record ); name: 'SecureProxyConnectionError'; code: 'UND_ERR_PRX_TLS';