Skip to content

Commit a81db18

Browse files
committed
fix: improve text/plain response handling with better error fallback
1 parent 51d3663 commit a81db18

File tree

1 file changed

+17
-7
lines changed
  • console/atest-ui/src/views

1 file changed

+17
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,24 @@ async function DefaultResponseProcess(response: any) {
2222
throw new Error("Unauthenticated")
2323
}
2424

25-
const message = await response.json().then((data: any) => data.message)
26-
throw new Error(message)
27-
} else {
28-
const contentType = response.headers.get('Content-Type') || '';
29-
if (contentType.includes('text/plain')) {
30-
return response.text();
25+
try {
26+
const message = await response.json().then((data: any) => data.message)
27+
throw new Error(message)
28+
} catch {
29+
const text = await response.text()
30+
throw new Error(text)
3131
}
32-
return response.json();
32+
}
33+
34+
const contentType = response.headers.get('Content-Type') || '';
35+
if (contentType.startsWith('text/plain')) {
36+
return response.text();
37+
}
38+
try {
39+
return await response.json();
40+
} catch (e) {
41+
// If JSON parsing fails, return as text
42+
return response.text();
3343
}
3444
}
3545

0 commit comments

Comments
 (0)