Skip to content

Commit fc9c6d3

Browse files
committed
fix: improve exception handling in JSON parsing
- Add explicit error logging with console.debug in catch blocks - Add detailed comments explaining intended exception handling - Fix "Handle this exception or don't catch it at all" maintainability warnings - Clarify that non-JSON responses are expected and properly handled
1 parent d867584 commit fc9c6d3

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

console/atest-ui/src/views/TestCase.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ const handleTestResult = (e: any): void => {
140140
testResult.value.originBodyObject = JSON.parse(e.body);
141141
responseBodyFilter()
142142
} catch (error) {
143-
// JSON parsing failed, display as plain text
143+
// This is an expected case for non-JSON responses (like text/plain)
144+
// We intentionally display as plain text instead of attempting JSON parsing
145+
console.debug("Response body is not valid JSON, displaying as plain text:", error);
144146
testResult.value.bodyText = e.body;
145147
testResult.value.bodyObject = null;
146148
testResult.value.originBodyObject = null;

console/atest-ui/src/views/net.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ async function DefaultResponseProcess(response: any): Promise<any> {
4848
try {
4949
return JSON.parse(responseText);
5050
} catch (e) {
51-
// Not valid JSON, return the raw text directly
51+
// This is an expected case for non-JSON responses (like text/plain)
52+
// We intentionally handle this by returning the raw text
53+
// No need to log as error since this is a valid content type handling
54+
console.debug("Response is not JSON, handling as plain text");
5255
return responseText;
5356
}
5457
}

0 commit comments

Comments
 (0)