File tree Expand file tree Collapse file tree 2 files changed +23
-12
lines changed
console/atest-ui/src/views Expand file tree Collapse file tree 2 files changed +23
-12
lines changed Original file line number Diff line number Diff line change @@ -124,9 +124,15 @@ const handleTestResult = (e: any) => {
124124 isResponseFile .value = true
125125 } else if (e .body !== ' ' ){
126126 testResult .value .bodyLength = e .body .length
127- testResult .value .bodyObject = JSON .parse (e .body );
128- testResult .value .originBodyObject = JSON .parse (e .body );
129- responseBodyFilter ()
127+ try {
128+ testResult .value .bodyObject = JSON .parse (e .body );
129+ testResult .value .originBodyObject = JSON .parse (e .body );
130+ responseBodyFilter ()
131+ } catch (error ) {
132+ testResult .value .bodyText = e .body ;
133+ testResult .value .bodyObject = null ;
134+ testResult .value .originBodyObject = null ;
135+ }
130136 }
131137
132138 Cache .SetTestCaseResponseCache (suite + ' -' + name , {
Original file line number Diff line number Diff line change @@ -30,16 +30,16 @@ async function DefaultResponseProcess(response: any) {
3030 throw new Error ( text )
3131 }
3232 }
33-
34- const contentType = response . headers . get ( 'Content-Type' ) || '' ;
35- if ( contentType . startsWith ( ' text/plain' ) ) {
36- return response . text ( ) ;
37- }
33+
34+ // 先获取响应文本
35+ const responseText = await response . text ( ) ;
36+
37+ // 尝试解析为JSON,如果失败则直接返回原始文本
3838 try {
39- return await response . json ( ) ;
39+ return JSON . parse ( responseText ) ;
4040 } catch ( e ) {
41- // If JSON parsing fails, return as text
42- return response . text ( ) ;
41+ // 不是有效的JSON,直接返回原始文本
42+ return responseText ;
4343 }
4444}
4545
@@ -768,7 +768,12 @@ function GetTestCaseAllHistory(req: TestCase,
768768 . then ( callback ) . catch ( errHandle )
769769}
770770
771- function DownloadResponseFile ( testcase ,
771+ interface ResponseFile {
772+ body : string ;
773+ [ key : string ] : any ;
774+ }
775+
776+ function DownloadResponseFile ( testcase : ResponseFile ,
772777 callback : ( d : any ) => void , errHandle ?: ( e : any ) => void | null ) {
773778 const requestOptions = {
774779 method : 'POST' ,
You can’t perform that action at this time.
0 commit comments