This is an automated email from the ASF dual-hosted git repository.

likeguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 88aa033c API-Debug page request result exception compatible handling 
(#322)
88aa033c is described below

commit 88aa033cd651c67e6d07851ccf0651d69273cb45
Author: Kerwin Bryant <[email protected]>
AuthorDate: Tue Aug 22 09:48:27 2023 +0800

    API-Debug page request result exception compatible handling (#322)
---
 package.json                               |  1 +
 src/routes/Document/components/ApiDebug.js | 19 +++++++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/package.json b/package.json
index beacd875..0f97f6ee 100755
--- a/package.json
+++ b/package.json
@@ -38,6 +38,7 @@
     "react-container-query": "^0.11.0",
     "react-document-title": "^2.0.3",
     "react-dom": "^16.13.1",
+    "react-html-parser": "^2.0.2",
     "react-intl-universal": "^2.4.2",
     "react-json-view": "^1.21.3",
     "react-resizable": "^1.11.0",
diff --git a/src/routes/Document/components/ApiDebug.js 
b/src/routes/Document/components/ApiDebug.js
index 06bb11d5..03f09bc2 100644
--- a/src/routes/Document/components/ApiDebug.js
+++ b/src/routes/Document/components/ApiDebug.js
@@ -18,6 +18,7 @@
 import {Button, Col, Empty, Form, Icon, Input, message, Row, Select, Tabs, 
Typography} from "antd";
 import React, {createRef, forwardRef, useContext, useEffect, 
useImperativeHandle, useState} from "react";
 import ReactJson from "react-json-view";
+import ReactHtmlParser from "react-html-parser";
 import fetch from "dva/fetch";
 import {
   createOrUpdateMockRequest,
@@ -359,12 +360,22 @@ function ApiDebug() {
       },
       body: JSON.stringify(params)
     }).then(async response => {
-      const data = await response.json();
+      const textData = await response.text();
+      let jsonData = null;
+      let type = 'text';
+      try {
+        jsonData = JSON.parse(textData);
+        type = 'json';
+      } catch (e) {
+        // eslint-disable-next-line no-console
+        console.error(e);
+      }
       setResponseInfo({
         "sandbox-params": response.headers.get("sandbox-params"),
         "sandbox-beforesign": response.headers.get("sandbox-beforesign"),
         "sandbox-sign": response.headers.get("sandbox-sign"),
-        body: data
+        body: type === 'json' ? jsonData : textData,
+        bodyType: type
       });
     });
   };
@@ -421,9 +432,9 @@ function ApiDebug() {
           tab={getIntlContent("SHENYU.DOCUMENT.APIDOC.INFO.REQUEST.RESULTS")}
           key="2"
         >
-          {Object.keys(responseInfo).length ? (
+          {responseInfo.bodyType === 'json' && 
Object.keys(responseInfo).length ? (
             <ReactJson src={responseInfo.body} name={false} />
-          ) : (
+          ) : responseInfo.body ? ReactHtmlParser(responseInfo.body) : (
             <Empty description={false} />
           )}
         </TabPane>

Reply via email to