From 1a5f42085e0ba81b3e675c1ba8535d093375385d Mon Sep 17 00:00:00 2001 From: Nut He <18328704+hetao92@users.noreply.github.com> Date: Mon, 30 May 2022 15:50:04 +0800 Subject: [PATCH] s This is the 1st commit message: (#233) fix: fix response type mod: code review --- app/pages/Import/FileUpload/FileList.tsx | 4 ++-- app/stores/files.ts | 2 +- app/utils/http.ts | 24 +++++++++---------- server/api/studio/internal/service/gateway.go | 5 ++-- server/api/studio/internal/types/types.go | 2 +- server/go.mod | 2 +- server/go.sum | 4 ++-- 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app/pages/Import/FileUpload/FileList.tsx b/app/pages/Import/FileUpload/FileList.tsx index 12f053e1..b22d85af 100644 --- a/app/pages/Import/FileUpload/FileList.tsx +++ b/app/pages/Import/FileUpload/FileList.tsx @@ -5,8 +5,8 @@ import Icon from '@app/components/Icon'; import CSVPreviewLink from '@app/components/CSVPreviewLink'; import { getFileSize } from '@app/utils/file'; import cls from 'classnames'; -import styles from './index.module.less'; import { StudioFile } from '@app/interfaces/import'; +import styles from './index.module.less'; interface IProps { fileList: any[]; onDelete: (index: number) => void; @@ -36,7 +36,7 @@ const FileList = (props: IProps) => { key: 'operation', render: (_, file, index) => { if(!file.content) { - return null + return null; } return (
diff --git a/app/stores/files.ts b/app/stores/files.ts index 56b53faf..aa4ddc96 100644 --- a/app/stores/files.ts +++ b/app/stores/files.ts @@ -22,7 +22,7 @@ export class FilesStore { const { code, data } = (await service.getFiles()) as any; if (code === 0 && data) { this.update({ - fileList: data, + fileList: data.list || [], }); } }; diff --git a/app/utils/http.ts b/app/utils/http.ts index e839eab1..fe6d7447 100644 --- a/app/utils/http.ts +++ b/app/utils/http.ts @@ -43,25 +43,25 @@ service.interceptors.request.use(config => { service.interceptors.response.use( (response: any) => { - - // const isExecReq = /api-nebula\/db\/(exec|batchExec)$/.test(response.config?.url); - if (response.data?.data?.data && Object.keys(response.data.data).length === 1) { - response.data.data = response.data.data.data; - } return response.data; }, (error: any) => { if (error.response?.status) { - message.error( - `${intl.get('common.requestError')}: ${error.response.status} ${ - error.response.statusText - }`, - ); + const res = error.response.data || {}; + if(res.code !== 0 && res.message) { + message.error(res.message); + } else { + message.error( + `${intl.get('common.requestError')}: ${error.response.status} ${ + error.response.statusText + }`, + ); + } // relogin - if (error.response.data?.code === HttpResCode.ErrSession) { + if (res.code === HttpResCode.ErrSession) { getRootStore().global.logout(); } - return error.response.data; + return res; } else { message.error(`${intl.get('common.requestError')}: ${error}`); return error; diff --git a/server/api/studio/internal/service/gateway.go b/server/api/studio/internal/service/gateway.go index 2237d318..95637700 100644 --- a/server/api/studio/internal/service/gateway.go +++ b/server/api/studio/internal/service/gateway.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/vesoft-inc/go-pkg/middleware" + "github.com/vesoft-inc/go-pkg/response" "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/gateway/dao" "github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/svc" "github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/types" @@ -114,7 +115,7 @@ func (s *gatewayService) ExecNGQL(request *types.ExecNGQLParams) (*types.AnyResp return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err, "execute failed") } - return &types.AnyResponse{Data: execute}, nil + return &types.AnyResponse{Data: response.StandardHandlerDataFieldAny(execute)}, nil } func (s *gatewayService) BatchExecNGQL(request *types.BatchExecNGQLParams) (*types.AnyResponse, error) { @@ -153,5 +154,5 @@ func (s *gatewayService) BatchExecNGQL(request *types.BatchExecNGQLParams) (*typ data = append(data, gqlRes) } - return &types.AnyResponse{Data: data}, nil + return &types.AnyResponse{Data: response.StandardHandlerDataFieldAny(data)}, nil } diff --git a/server/api/studio/internal/types/types.go b/server/api/studio/internal/types/types.go index 78f4c084..c5e7e899 100644 --- a/server/api/studio/internal/types/types.go +++ b/server/api/studio/internal/types/types.go @@ -42,7 +42,7 @@ type FileStat struct { } type FilesIndexData struct { - List []FileStat `json:"data"` + List []FileStat `json:"list"` } type ImportTaskConnection struct { diff --git a/server/go.mod b/server/go.mod index 066dbe7f..d9790315 100644 --- a/server/go.mod +++ b/server/go.mod @@ -3,7 +3,7 @@ module github.com/vesoft-inc/nebula-studio/server-v2 go 1.17 require ( - github.com/vesoft-inc/go-pkg v0.0.0-20220516090733-5ce93ad3254b + github.com/vesoft-inc/go-pkg v0.0.0-20220530040051-17c1bd2e8dd4 github.com/vesoft-inc/nebula-importer v1.0.1-0.20220505095506-93febd41c2be github.com/zeromicro/go-zero v1.3.3 ) diff --git a/server/go.sum b/server/go.sum index 40dc345d..25ed90a4 100644 --- a/server/go.sum +++ b/server/go.sum @@ -398,8 +398,8 @@ github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMT github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= -github.com/vesoft-inc/go-pkg v0.0.0-20220516090733-5ce93ad3254b h1:MVAkGU2YH1p3PhWN0T+r0bkv+gn5b33J2tEdnXXZAUE= -github.com/vesoft-inc/go-pkg v0.0.0-20220516090733-5ce93ad3254b/go.mod h1:HCAXRhF2io+nPLQnl+RQ6XyVcp1Xdv6NgslXRBBCiEU= +github.com/vesoft-inc/go-pkg v0.0.0-20220530040051-17c1bd2e8dd4 h1:PIHQdemdD/YrOHJtPUTpC1+BpcKokuj1HXyGo6CErjM= +github.com/vesoft-inc/go-pkg v0.0.0-20220530040051-17c1bd2e8dd4/go.mod h1:HCAXRhF2io+nPLQnl+RQ6XyVcp1Xdv6NgslXRBBCiEU= github.com/vesoft-inc/nebula-go/v3 v3.0.0-20220425030225-cdb52399b40a h1:/8l9RT6gU0cUS1Cgzqv3A9dKto19VQBjVk1BqAAqqvM= github.com/vesoft-inc/nebula-go/v3 v3.0.0-20220425030225-cdb52399b40a/go.mod h1:+sXv05jYQBARdTbTcIEsWVXCnF/6ttOlDK35xQ6m54s= github.com/vesoft-inc/nebula-http-gateway/ccore v0.0.0-20220518092450-316a5f6420ef h1:Hco8JsAXm2ujRpJjo+qGnVyASHXDnopHwA20anmmnV4=