Visual improvements to debug mode for better information visibility
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
function createDebugContentLog({
|
||||
previewDebugBody,
|
||||
DEBUG_BODY_LIMIT,
|
||||
debugState,
|
||||
renderDebugPanel
|
||||
@@ -98,17 +99,7 @@ function createDebugContentLog({
|
||||
}
|
||||
|
||||
function createDebugBody(text) {
|
||||
if (text.length > DEBUG_BODY_LIMIT) {
|
||||
return {
|
||||
value: `${text.slice(0, DEBUG_BODY_LIMIT)}\n... truncated ${text.length - DEBUG_BODY_LIMIT} characters`,
|
||||
truncated: true
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
value: text || "(empty response body)",
|
||||
truncated: false
|
||||
};
|
||||
return previewDebugBody(text, DEBUG_BODY_LIMIT);
|
||||
}
|
||||
|
||||
function headersToObject(headers) {
|
||||
@@ -137,13 +128,16 @@ function createDebugContentLog({
|
||||
|
||||
function formatDebugBody(body) {
|
||||
const text = body || "(none)";
|
||||
|
||||
if (debugState.debugSecretsVisible) {
|
||||
return text;
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.stringify(maskSensitiveDebugValue(JSON.parse(text)), null, 2);
|
||||
const normalized = String(text).replace(/^\uFEFF/, "").trimStart()
|
||||
.replace(/^\)\]\}',?\s*/, "")
|
||||
.replace(/^while\s*\(1\);\s*/, "");
|
||||
let value = JSON.parse(normalized);
|
||||
// Some services serialize their JSON document inside a JSON string.
|
||||
for (let depth = 0; depth < 2 && typeof value === "string" && /^[\s]*[\[{]/.test(value); depth += 1) {
|
||||
try { value = JSON.parse(value); } catch { break; }
|
||||
}
|
||||
return JSON.stringify(debugState.debugSecretsVisible ? value : maskSensitiveDebugValue(value), null, 2);
|
||||
} catch (error) {
|
||||
return text;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user