Skip to content

Commit

Permalink
refactor: throw error and add test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
luddd3 committed Dec 18, 2024
1 parent 46c6d06 commit aa465fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/interceptor/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ module.exports = interceptorOpts => {
return (dispatch, opts) => {
return function dnsInterceptor (origDispatchOpts, handler) {
if (!origDispatchOpts.origin) {
return handler.onResponseError(null, new InvalidArgumentError('Origin Missing'))
throw new InvalidArgumentError('Origin missing')
}

const origin = origDispatchOpts.origin.constructor === URL
Expand Down
19 changes: 19 additions & 0 deletions test/interceptors/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ test('Should validate options', t => {
t.throws(() => dns({ pick: [] }), { code: 'UND_ERR_INVALID_ARG' })
})

test('Should throw when origin is missing', async t => {
t = tspl(t, { plan: 1 })
const client = new Agent().compose([
dns()
])

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

let error
try {
await client.request({})
} catch (err) {
error = err
}
t.equal(error.code, 'UND_ERR_INVALID_ARG')
})

test('Should automatically resolve IPs (dual stack)', async t => {
t = tspl(t, { plan: 8 })

Expand Down

0 comments on commit aa465fb

Please sign in to comment.