Skip to content

Commit

Permalink
fix: instantiation of SecureProxyConnectionError should pass options …
Browse files Browse the repository at this point in the history
…to parent class (#3473)

* fix: instantiation of SecureProxyConnectionError should pass options to parent class

* fix typescript error by making cause optional

* fix ts error
  • Loading branch information
Uzlopak authored Aug 19, 2024
1 parent e27e0f6 commit c1654af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/core/errors.js
Original file line number Diff line number Diff line change
@@ -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'
}
Expand Down Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion test/proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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')
}

Expand Down
5 changes: 5 additions & 0 deletions types/errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ declare namespace Errors {
}

export class SecureProxyConnectionError extends UndiciError {
constructor (
cause?: Error,
message?: string,
options?: Record<any, any>
);
name: 'SecureProxyConnectionError';
code: 'UND_ERR_PRX_TLS';
}
Expand Down

0 comments on commit c1654af

Please sign in to comment.