mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-29 14:31:35 +08:00
fix(MessageTools): improve error handling and logging in message preview rendering (#8453)
- Enhanced the rendering logic for message previews by adding a try-catch block to handle JSON parsing errors more gracefully. - Updated the error handling to provide clearer error messages in the preview when exceptions occur. - Added debug logging to track the rendering process of message content.
This commit is contained in:
parent
06dd581fc3
commit
85347885bd
@ -280,22 +280,37 @@ const MessageTools: FC<Props> = ({ block }) => {
|
||||
if (!content) return null
|
||||
|
||||
try {
|
||||
logger.debug(`renderPreview: ${content}`)
|
||||
const parsedResult = JSON.parse(content)
|
||||
switch (parsedResult.content[0]?.type) {
|
||||
case 'text':
|
||||
return (
|
||||
<CollapsedContent
|
||||
isExpanded={true}
|
||||
resultString={JSON.stringify(JSON.parse(parsedResult.content[0].text), null, 2)}
|
||||
/>
|
||||
)
|
||||
try {
|
||||
return (
|
||||
<CollapsedContent
|
||||
isExpanded={true}
|
||||
resultString={JSON.stringify(JSON.parse(parsedResult.content[0].text), null, 2)}
|
||||
/>
|
||||
)
|
||||
} catch (e) {
|
||||
return (
|
||||
<CollapsedContent
|
||||
isExpanded={true}
|
||||
resultString={JSON.stringify(parsedResult.content[0].text, null, 2)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
default:
|
||||
return <CollapsedContent isExpanded={true} resultString={JSON.stringify(parsedResult, null, 2)} />
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error('failed to render the preview of mcp results:', e as Error)
|
||||
return <CollapsedContent isExpanded={true} resultString={JSON.stringify(e, null, 2)} />
|
||||
return (
|
||||
<CollapsedContent
|
||||
isExpanded={true}
|
||||
resultString={e instanceof Error ? e.message : JSON.stringify(e, null, 2)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user