mirror of
https://github.com/ChromeDevTools/chrome-devtools-mcp.git
synced 2026-09-14 19:45:30 +08:00
fix(clI): print the errror message alone instead of JSON in the CLI (#2580)
Currently we print the JSON structure even when used in the CLI.
This commit is contained in:
@@ -224,6 +224,15 @@ export async function handleResponse(
|
||||
format: 'json' | 'md',
|
||||
): Promise<string> {
|
||||
if (response.isError) {
|
||||
if (format === 'md') {
|
||||
const chunks = [];
|
||||
for (const content of response.content) {
|
||||
if (content.type === 'text') {
|
||||
chunks.push(content.text);
|
||||
}
|
||||
}
|
||||
return chunks.join(' ');
|
||||
}
|
||||
return JSON.stringify(response.content);
|
||||
}
|
||||
const chunks = [];
|
||||
|
||||
@@ -126,13 +126,24 @@ describe('daemon client', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('handles error response when isError is true', async () => {
|
||||
it('handles error response when isError is true with md format', async () => {
|
||||
const errorResponse = {
|
||||
isError: true,
|
||||
content: [{type: 'text' as const, text: 'Something went wrong'}],
|
||||
};
|
||||
assert.strictEqual(
|
||||
await handleResponse(errorResponse, 'md'),
|
||||
'Something went wrong',
|
||||
);
|
||||
});
|
||||
|
||||
it('handles error response when isError is true with json format', async () => {
|
||||
const errorResponse = {
|
||||
isError: true,
|
||||
content: [{type: 'text' as const, text: 'Something went wrong'}],
|
||||
};
|
||||
assert.strictEqual(
|
||||
await handleResponse(errorResponse, 'json'),
|
||||
JSON.stringify(errorResponse.content),
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user