fix debug logging of undefined query params (#8540)
This commit is contained in:
@@ -222,7 +222,13 @@ class BaseService {
|
|||||||
let logUrl = url
|
let logUrl = url
|
||||||
const logOptions = Object.assign({}, options)
|
const logOptions = Object.assign({}, options)
|
||||||
if ('searchParams' in 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()}`
|
logUrl = `${url}?${params.toString()}`
|
||||||
delete logOptions.searchParams
|
delete logOptions.searchParams
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -440,14 +440,21 @@ describe('BaseService', function () {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const url = 'some-url'
|
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 })
|
await serviceInstance._request({ url, options })
|
||||||
|
|
||||||
expect(trace.logTrace).to.be.calledWithMatch(
|
expect(trace.logTrace).to.be.calledWithMatch(
|
||||||
'fetch',
|
'fetch',
|
||||||
sinon.match.string,
|
sinon.match.string,
|
||||||
'Request',
|
'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(
|
expect(trace.logTrace).to.be.calledWithMatch(
|
||||||
'fetch',
|
'fetch',
|
||||||
|
|||||||
Reference in New Issue
Block a user