Просмотр исходного кода

imprv: apiv3 client (#4770)

* Change apiv3Request to return res instead of res.data

* * Checked and traced apiv3 methods in this project:

- apiv3.get
- apiv3.post
- apiv3.put
- apiv3.delete

- apiv3Get
- apiv3Post
- apiv3Put
- apiv3Delete

Result:
- Almost all apiv3 methods implementing AxiosResponse obj type but there are 3 request that need to extra check
- Added TODO for those three files

* - Fix response to return original obj

* - Checking and remove TODO comments

* - Fix error ElasticsearchMnagement.regreieveIndicesStatus() API implementation
Luqman Grune 4 лет назад
Родитель
Сommit
6853de5c6a

+ 1 - 1
packages/app/src/client/util/apiv3-client.ts

@@ -36,7 +36,7 @@ const apiv3ErrorHandler = (_err) => {
 export async function apiv3Request<T = any>(method: string, path: string, params: unknown): Promise<AxiosResponse<T>> {
   try {
     const res = await axios[method](urljoin(apiv3Root, path), params);
-    return res.data;
+    return res;
   }
   catch (err) {
     const errors = apiv3ErrorHandler(err);

+ 2 - 1
packages/app/src/components/Admin/ElasticsearchManagement/ElasticsearchManagement.jsx

@@ -70,7 +70,8 @@ class ElasticsearchManagement extends React.Component {
     const { appContainer } = this.props;
 
     try {
-      const { info } = await appContainer.apiv3Get('/search/indices');
+      const { data } = await appContainer.apiv3Get('/search/indices');
+      const { info } = data;
 
       this.setState({
         isConnected: true,

+ 1 - 1
packages/app/src/server/routes/apiv3/response.js

@@ -10,7 +10,7 @@ const addCustomFunctionToResponse = (express, crowi) => {
       throw new Error('invalid value supplied to res.apiv3');
     }
 
-    this.status(status).json({ data: obj });
+    this.status(status).json(obj);
   };
 
   express.response.apiv3Err = function(_err, status = 400, info) { // not arrow function