fix debug logging of undefined query params (#8540)

This commit is contained in:
chris48s
2022-12-28 19:54:11 +00:00
committed by GitHub
parent 7a38cfe099
commit 00f35c67e8
2 changed files with 16 additions and 3 deletions

View File

@@ -222,7 +222,13 @@ class BaseService {
let logUrl = url
const logOptions = Object.assign({}, options)
if ('searchParams' in options) {
const params = new URLSearchParams(options.searchParams)
const params = new URLSearchParams(
Object.fromEntries(
Object.entries(options.searchParams).filter(
([k, v]) => v !== undefined
)
)
)
logUrl = `${url}?${params.toString()}`
delete logOptions.searchParams
}

View File

@@ -440,14 +440,21 @@ describe('BaseService', function () {
)
const url = 'some-url'
const options = { headers: { Cookie: 'some-cookie' } }
const options = {
headers: { Cookie: 'some-cookie' },
searchParams: { param1: 'foobar', param2: undefined },
}
await serviceInstance._request({ url, options })
expect(trace.logTrace).to.be.calledWithMatch(
'fetch',
sinon.match.string,
'Request',
`${url}\n${JSON.stringify(options, null, 2)}`
`${url}?param1=foobar\n${JSON.stringify(
{ headers: options.headers },
null,
2
)}`
)
expect(trace.logTrace).to.be.calledWithMatch(
'fetch',