7a918bb9f4eaf1d7b588152d35290268ced89aa5
4 * Pick out useful got response fields.
5 * @param {GotResponse} res
8 const gotResponseLogData
= (res
) => {
9 const data
= pick(res
, [
16 if (typeof res
.body
=== 'string') {
17 data
.body
= logTruncate(data
.body
, 100);
18 } else if (res
.body
instanceof Buffer
) {
19 data
.body
= `<Buffer ${res.body.byteLength} bytes>`;
21 data
.elapsedTimeMs
= res
?.timings
?.phases
?.total
;
22 if (res
?.redirectUrls
?.length
) {
23 data
.redirectUrls
= res
.redirectUrls
;
25 if (res
?.retryCount
) {
26 data
.retryCount
= res
.retryCount
;
33 * Limit length of string to keep logs sane
38 const logTruncate
= (str
, len
) => {
39 if (typeof str
!== 'string' || str
.toString().length
<= len
) {
42 return str
.toString().slice(0, len
) + `... (${str.toString().length} bytes)`;
47 * Return a new object with selected props.
49 * @param {String[]} props
51 const pick
= (obj
, props
) => {
52 return props
.reduce((acc
, prop
) => {
54 acc
[prop
] = obj
[prop
]; // eslint-disable-line security/detect-object-injection
62 * Return a set containing non-shared items between two sets.
67 const setSymmetricDifference
= (a
, b
) => {
81 * URL objects have weird names.
82 * @param {String} component
85 const properURLComponentName
= (component
) => {
86 // eslint-disable-next-line security/detect-object-injection
90 }[component
] || component
;
98 setSymmetricDifference
,
99 properURLComponentName
,