Skip to content

Commit d2016a5

Browse files
Fix debug logging for body types
1 parent 551fbf7 commit d2016a5

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

index.html

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,18 @@
452452
}
453453
}
454454

455-
console.log(`HTTP ${method} ${url}`, {
456-
bodySize: requestBody?.length,
457-
bodyType: requestBody?.constructor?.name,
458-
bodyStart: requestBody ? new TextDecoder().decode(requestBody.slice(0, 50)) : null
459-
});
455+
if (requestBody) {
456+
const preview = requestBody instanceof Uint8Array
457+
? new TextDecoder().decode(requestBody.slice(0, 50))
458+
: String(requestBody).slice(0, 50);
459+
console.log(`HTTP ${method} ${url}`, {
460+
bodySize: requestBody.length || requestBody.byteLength,
461+
bodyType: requestBody.constructor?.name,
462+
bodyStart: preview
463+
});
464+
} else {
465+
console.log(`HTTP ${method} ${url} (no body)`);
466+
}
460467

461468
// Make the request
462469
const res = await fetch(url, {

0 commit comments

Comments
 (0)