Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: response error interceptor #3930

Merged
merged 1 commit into from
Dec 8, 2024
Merged
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
4 changes: 2 additions & 2 deletions lib/interceptor/response-error.js
Original file line number Diff line number Diff line change
@@ -81,8 +81,8 @@ class ResponseErrorHandler extends DecoratorHandler {
}
}

onResponseError (err) {
super.onResponseError(err)
onResponseError (controller, err) {
super.onResponseError(controller, err)
}
}

25 changes: 25 additions & 0 deletions test/interceptors/response-error.js
Original file line number Diff line number Diff line change
@@ -168,3 +168,28 @@ test('should throw error for error response, parsing JSON without charset', asyn
message: 'Bad Request'
})
})

test('should throw error for networking errors response', async () => {
const client = new Client(
'http://localhost:12345'
).compose(responseError())

after(async () => {
await client.close()
})

let error
try {
await client.request({
method: 'GET',
path: '/',
headers: {
'content-type': 'text/plain'
}
})
} catch (err) {
error = err
}

assert.equal(error.code, 'ECONNREFUSED')
})

Unchanged files with check annotations Beta

test('https get with tls opts', async (t) => {
t = tspl(t, { plan: 6 })
const server = createServer(pem, (req, res) => {

Check failure on line 12 in test/https.js

GitHub Actions / test (23, macos-latest) / Test with Node.js 23 on macos-latest

https get with tls opts

[Error [ERR_TEST_FAILURE]: error:068000DD:asn1 encoding routines::illegal padding] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: error:068000DD:asn1 encoding routines::illegal padding at node:internal/tls/secure-context:70:13 at Array.forEach (<anonymous>) at setCerts (node:internal/tls/secure-context:68:3) at configSecureContext (node:internal/tls/secure-context:191:5) at Object.createSecureContext (node:_tls_common:113:3) at Server.setSecureContext (node:_tls_wrap:1490:27) at Server (node:_tls_wrap:1354:8) at new Server (node:https:80:3) at createServer (node:https:135:10) at TestContext.<anonymous> (/Users/runner/work/undici/undici/test/https.js:12:18) { opensslErrorStack: [ 'error:0488000D:PEM routines::ASN1 lib', 'error:0688010A:asn1 encoding routines::nested asn1 error', 'error:0688010A:asn1 encoding routines::nested asn1 error' ], library: 'asn1 encoding routines', reason: 'illegal padding', code: 'ERR_OSSL_ASN1_ILLEGAL_PADDING' } }
t.strictEqual('/', req.url)
t.strictEqual('GET', req.method)
res.setHeader('content-type', 'text/plain')
test('https get with tls opts ip', async (t) => {
t = tspl(t, { plan: 6 })
const server = createServer(pem, (req, res) => {

Check failure on line 48 in test/https.js

GitHub Actions / test (23, macos-latest) / Test with Node.js 23 on macos-latest

https get with tls opts ip

[Error [ERR_TEST_FAILURE]: error:068000DD:asn1 encoding routines::illegal padding] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: error:068000DD:asn1 encoding routines::illegal padding at node:internal/tls/secure-context:70:13 at Array.forEach (<anonymous>) at setCerts (node:internal/tls/secure-context:68:3) at configSecureContext (node:internal/tls/secure-context:191:5) at Object.createSecureContext (node:_tls_common:113:3) at Server.setSecureContext (node:_tls_wrap:1490:27) at Server (node:_tls_wrap:1354:8) at new Server (node:https:80:3) at createServer (node:https:135:10) at TestContext.<anonymous> (/Users/runner/work/undici/undici/test/https.js:48:18) { opensslErrorStack: [ 'error:0488000D:PEM routines::ASN1 lib', 'error:0688010A:asn1 encoding routines::nested asn1 error', 'error:0688010A:asn1 encoding routines::nested asn1 error' ], library: 'asn1 encoding routines', reason: 'illegal padding', code: 'ERR_OSSL_ASN1_ILLEGAL_PADDING' } }
t.strictEqual('/', req.url)
t.strictEqual('GET', req.method)
res.setHeader('content-type', 'text/plain')
test('Should support H2 connection', async t => {
const body = []
const server = createSecureServer(pem)

Check failure on line 19 in test/http2.js

GitHub Actions / test (23, macos-latest) / Test with Node.js 23 on macos-latest

Should support H2 connection

[Error [ERR_TEST_FAILURE]: error:068000DD:asn1 encoding routines::illegal padding] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: error:068000DD:asn1 encoding routines::illegal padding at node:internal/tls/secure-context:70:13 at Array.forEach (<anonymous>) at setCerts (node:internal/tls/secure-context:68:3) at configSecureContext (node:internal/tls/secure-context:191:5) at Object.createSecureContext (node:_tls_common:113:3) at Server.setSecureContext (node:_tls_wrap:1490:27) at new Server (node:_tls_wrap:1354:8) at new Http2SecureServer (node:internal/http2/core:3155:5) at createSecureServer (node:internal/http2/core:3366:10) at TestContext.<anonymous> (/Users/runner/work/undici/undici/test/http2.js:19:18) { opensslErrorStack: [ 'error:0488000D:PEM routines::ASN1 lib', 'error:0688010A:asn1 encoding routines::nested asn1 error', 'error:0688010A:asn1 encoding routines::nested asn1 error' ], library: 'asn1 encoding routines', reason: 'illegal padding', code: 'ERR_OSSL_ASN1_ILLEGAL_PADDING' } }
server.on('stream', (stream, headers, _flags, rawHeaders) => {
t.strictEqual(headers['x-my-header'], 'foo')
})
test('Should support H2 connection(multiple requests)', async t => {
const server = createSecureServer(pem)

Check failure on line 66 in test/http2.js

GitHub Actions / test (23, macos-latest) / Test with Node.js 23 on macos-latest

Should support H2 connection(multiple requests)

[Error [ERR_TEST_FAILURE]: error:068000DD:asn1 encoding routines::illegal padding] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: error:068000DD:asn1 encoding routines::illegal padding at node:internal/tls/secure-context:70:13 at Array.forEach (<anonymous>) at setCerts (node:internal/tls/secure-context:68:3) at configSecureContext (node:internal/tls/secure-context:191:5) at Object.createSecureContext (node:_tls_common:113:3) at Server.setSecureContext (node:_tls_wrap:1490:27) at new Server (node:_tls_wrap:1354:8) at new Http2SecureServer (node:internal/http2/core:3155:5) at createSecureServer (node:internal/http2/core:3366:10) at TestContext.<anonymous> (/Users/runner/work/undici/undici/test/http2.js:66:18) { opensslErrorStack: [ 'error:0488000D:PEM routines::ASN1 lib', 'error:0688010A:asn1 encoding routines::nested asn1 error', 'error:0688010A:asn1 encoding routines::nested asn1 error' ], library: 'asn1 encoding routines', reason: 'illegal padding', code: 'ERR_OSSL_ASN1_ILLEGAL_PADDING' } }
server.on('stream', async (stream, headers, _flags, rawHeaders) => {
t.strictEqual(headers['x-my-header'], 'foo')
test('Should support H2 connection (headers as array)', async t => {
const body = []
const server = createSecureServer(pem)

Check failure on line 125 in test/http2.js

GitHub Actions / test (23, macos-latest) / Test with Node.js 23 on macos-latest

Should support H2 connection (headers as array)

[Error [ERR_TEST_FAILURE]: error:068000DD:asn1 encoding routines::illegal padding] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: error:068000DD:asn1 encoding routines::illegal padding at node:internal/tls/secure-context:70:13 at Array.forEach (<anonymous>) at setCerts (node:internal/tls/secure-context:68:3) at configSecureContext (node:internal/tls/secure-context:191:5) at Object.createSecureContext (node:_tls_common:113:3) at Server.setSecureContext (node:_tls_wrap:1490:27) at new Server (node:_tls_wrap:1354:8) at new Http2SecureServer (node:internal/http2/core:3155:5) at createSecureServer (node:internal/http2/core:3366:10) at TestContext.<anonymous> (/Users/runner/work/undici/undici/test/http2.js:125:18) { opensslErrorStack: [ 'error:0488000D:PEM routines::ASN1 lib', 'error:0688010A:asn1 encoding routines::nested asn1 error', 'error:0688010A:asn1 encoding routines::nested asn1 error' ], library: 'asn1 encoding routines', reason: 'illegal padding', code: 'ERR_OSSL_ASN1_ILLEGAL_PADDING' } }
server.on('stream', (stream, headers) => {
t.strictEqual(headers['x-my-header'], 'foo')
})
test('Should support H2 connection(POST Buffer)', async t => {
const server = createSecureServer({ ...pem, allowHTTP1: false })

Check failure on line 171 in test/http2.js

GitHub Actions / test (23, macos-latest) / Test with Node.js 23 on macos-latest

Should support H2 connection(POST Buffer)

[Error [ERR_TEST_FAILURE]: error:068000DD:asn1 encoding routines::illegal padding] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: error:068000DD:asn1 encoding routines::illegal padding at node:internal/tls/secure-context:70:13 at Array.forEach (<anonymous>) at setCerts (node:internal/tls/secure-context:68:3) at configSecureContext (node:internal/tls/secure-context:191:5) at Object.createSecureContext (node:_tls_common:113:3) at Server.setSecureContext (node:_tls_wrap:1490:27) at new Server (node:_tls_wrap:1354:8) at new Http2SecureServer (node:internal/http2/core:3155:5) at createSecureServer (node:internal/http2/core:3366:10) at TestContext.<anonymous> (/Users/runner/work/undici/undici/test/http2.js:171:18) { opensslErrorStack: [ 'error:0488000D:PEM routines::ASN1 lib', 'error:0688010A:asn1 encoding routines::nested asn1 error', 'error:0688010A:asn1 encoding routines::nested asn1 error' ], library: 'asn1 encoding routines', reason: 'illegal padding', code: 'ERR_OSSL_ASN1_ILLEGAL_PADDING' } }
server.on('stream', async (stream, headers, _flags, rawHeaders) => {
t.strictEqual(headers[':method'], 'POST')
'[v20] Request should fail if allowH2 is false and server advertises h1 only',
{ skip: !isGreaterThanv20 },
async t => {
const server = createSecureServer(

Check failure on line 314 in test/http2.js

GitHub Actions / test (23, macos-latest) / Test with Node.js 23 on macos-latest

[v20] Request should fail if allowH2 is false and server advertises h1 only

[Error [ERR_TEST_FAILURE]: error:068000DD:asn1 encoding routines::illegal padding] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: error:068000DD:asn1 encoding routines::illegal padding at node:internal/tls/secure-context:70:13 at Array.forEach (<anonymous>) at setCerts (node:internal/tls/secure-context:68:3) at configSecureContext (node:internal/tls/secure-context:191:5) at Object.createSecureContext (node:_tls_common:113:3) at Server.setSecureContext (node:_tls_wrap:1490:27) at new Server (node:_tls_wrap:1354:8) at new Http2SecureServer (node:internal/http2/core:3155:5) at createSecureServer (node:internal/http2/core:3366:10) at TestContext.<anonymous> (/Users/runner/work/undici/undici/test/http2.js:314:20) { opensslErrorStack: [ 'error:0488000D:PEM routines::ASN1 lib', 'error:0688010A:asn1 encoding routines::nested asn1 error', 'error:0688010A:asn1 encoding routines::nested asn1 error' ], library: 'asn1 encoding routines', reason: 'illegal padding', code: 'ERR_OSSL_ASN1_ILLEGAL_PADDING' } }
{
...pem,
allowHTTP1: false,
test('Should handle h2 continue', async t => {
const requestBody = []
const server = createSecureServer(pem, () => {})

Check failure on line 351 in test/http2.js

GitHub Actions / test (23, macos-latest) / Test with Node.js 23 on macos-latest

Should handle h2 continue

[Error [ERR_TEST_FAILURE]: error:068000DD:asn1 encoding routines::illegal padding] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: error:068000DD:asn1 encoding routines::illegal padding at node:internal/tls/secure-context:70:13 at Array.forEach (<anonymous>) at setCerts (node:internal/tls/secure-context:68:3) at configSecureContext (node:internal/tls/secure-context:191:5) at Object.createSecureContext (node:_tls_common:113:3) at Server.setSecureContext (node:_tls_wrap:1490:27) at new Server (node:_tls_wrap:1354:8) at new Http2SecureServer (node:internal/http2/core:3155:5) at createSecureServer (node:internal/http2/core:3366:10) at TestContext.<anonymous> (/Users/runner/work/undici/undici/test/http2.js:351:18) { opensslErrorStack: [ 'error:0488000D:PEM routines::ASN1 lib', 'error:0688010A:asn1 encoding routines::nested asn1 error', 'error:0688010A:asn1 encoding routines::nested asn1 error' ], library: 'asn1 encoding routines', reason: 'illegal padding', code: 'ERR_OSSL_ASN1_ILLEGAL_PADDING' } }
const responseBody = []
server.on('checkContinue', (request, response) => {
})
test('Dispatcher#Stream', async t => {
const server = createSecureServer(pem)

Check failure on line 407 in test/http2.js

GitHub Actions / test (23, macos-latest) / Test with Node.js 23 on macos-latest

Dispatcher#Stream

[Error [ERR_TEST_FAILURE]: error:068000DD:asn1 encoding routines::illegal padding] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: error:068000DD:asn1 encoding routines::illegal padding at node:internal/tls/secure-context:70:13 at Array.forEach (<anonymous>) at setCerts (node:internal/tls/secure-context:68:3) at configSecureContext (node:internal/tls/secure-context:191:5) at Object.createSecureContext (node:_tls_common:113:3) at Server.setSecureContext (node:_tls_wrap:1490:27) at new Server (node:_tls_wrap:1354:8) at new Http2SecureServer (node:internal/http2/core:3155:5) at createSecureServer (node:internal/http2/core:3366:10) at TestContext.<anonymous> (/Users/runner/work/undici/undici/test/http2.js:407:18) { opensslErrorStack: [ 'error:0488000D:PEM routines::ASN1 lib', 'error:0688010A:asn1 encoding routines::nested asn1 error', 'error:0688010A:asn1 encoding routines::nested asn1 error' ], library: 'asn1 encoding routines', reason: 'illegal padding', code: 'ERR_OSSL_ASN1_ILLEGAL_PADDING' } }
const expectedBody = 'hello from client!'
const bufs = []
let requestBody = ''
})
test('Dispatcher#Pipeline', async t => {
const server = createSecureServer(pem)

Check failure on line 458 in test/http2.js

GitHub Actions / test (23, macos-latest) / Test with Node.js 23 on macos-latest

Dispatcher#Pipeline

[Error [ERR_TEST_FAILURE]: error:068000DD:asn1 encoding routines::illegal padding] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Error: error:068000DD:asn1 encoding routines::illegal padding at node:internal/tls/secure-context:70:13 at Array.forEach (<anonymous>) at setCerts (node:internal/tls/secure-context:68:3) at configSecureContext (node:internal/tls/secure-context:191:5) at Object.createSecureContext (node:_tls_common:113:3) at Server.setSecureContext (node:_tls_wrap:1490:27) at new Server (node:_tls_wrap:1354:8) at new Http2SecureServer (node:internal/http2/core:3155:5) at createSecureServer (node:internal/http2/core:3366:10) at TestContext.<anonymous> (/Users/runner/work/undici/undici/test/http2.js:458:18) { opensslErrorStack: [ 'error:0488000D:PEM routines::ASN1 lib', 'error:0688010A:asn1 encoding routines::nested asn1 error', 'error:0688010A:asn1 encoding routines::nested asn1 error' ], library: 'asn1 encoding routines', reason: 'illegal padding', code: 'ERR_OSSL_ASN1_ILLEGAL_PADDING' } }
const expectedBody = 'hello from client!'
const bufs = []
let requestBody = ''