Skip to content

Commit

Permalink
fix debug logging of undefined query params (#8540)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Dec 28, 2022
1 parent 7a38cfe commit 00f35c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion core/base-service/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 9 additions & 2 deletions core/base-service/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 00f35c6

Please sign in to comment.