Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ interface QueryDebuggerTabsProps {
onRunClick: () => void;
showSchema?: boolean;
}
const parseResponseBody = (body: any): any[] => {
let parsedOutput: any;

if (typeof body === "string") {
try {
parsedOutput = JSON.parse(body);
} catch (e) {
return [{ response: body }];
}
} else {
parsedOutput = body;
}

if (Array.isArray(parsedOutput)) {
return parsedOutput;
}
if (parsedOutput.records && Array.isArray(parsedOutput.records)) {
return parsedOutput.records;
}
return [parsedOutput];
};

function QueryDebuggerTabs({
actionName,
Expand Down Expand Up @@ -154,7 +175,7 @@ function QueryDebuggerTabs({
if (isString(actionResponse.body)) {
try {
// Try to parse response as JSON array to be displayed in the Response tab
output = JSON.parse(actionResponse.body);
output = parseResponseBody(actionResponse.body);
} catch (e) {
// In case the string is not a JSON, wrap it in a response object
output = [
Expand All @@ -163,10 +184,9 @@ function QueryDebuggerTabs({
},
];
}
} else {
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
output = actionResponse.body as any;
} else {
output = parseResponseBody(actionResponse.body);

}
}

Expand Down