Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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