提交 344f4819 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

send zentao request error to client

上级 bd1dc70f
package commConsts
type ResponseCode struct {
Code int64 `json:"code"`
Key string `json:"message"`
Code int64 `json:"code"`
Message string `json:"message"`
}
var (
Success = ResponseCode{0, "request_success"}
CommErr = ResponseCode{100, "comm_err"}
ParamErr = ResponseCode{200, "param_error"}
NeedInitErr = ResponseCode{1000, "data_not_init"}
BizErrWorkspaceConfig = ResponseCode{2000, "workspace_config_err"}
BizErrNameNotExist = ResponseCode{3000, "record_not_found_by_name"}
Success = ResponseCode{0, "request success"}
CommErr = ResponseCode{100, "common err"}
ParamErr = ResponseCode{200, "param error"}
UnAuthorizedErr = ResponseCode{401, "unauthorized"}
NeedInitErr = ResponseCode{1000, "data not init"}
BizErrZentaoRequest = ResponseCode{2000, "zentao request err"}
BizErrNameNotExist = ResponseCode{3000, "record not found"}
)
type ResultStatus string
......
......@@ -89,7 +89,7 @@ func LoadSiteProduct(currSite serverDomain.ZentaoSite, currProductId int) (
products, err = loadProduct(config)
if err != nil {
products = make([]serverDomain.ZentaoProduct, 0)
return
}
var first serverDomain.ZentaoProduct
......
......@@ -9,6 +9,7 @@ import (
"github.com/aaronchen2k/deeptest/internal/pkg/lib/log"
serverDomain "github.com/aaronchen2k/deeptest/internal/server/modules/v1/domain"
"github.com/ajg/form"
"github.com/bitly/go-simplejson"
"github.com/fatih/color"
"io/ioutil"
"net/http"
......@@ -51,6 +52,16 @@ func Get(url string) (ret []byte, err error) {
logUtils.Infof(logUtils.ConvertUnicode(ret))
}
jsn, err := simplejson.NewJson(ret)
if err != nil {
return
}
errMsg, _ := jsn.Get("error").String()
if strings.ToLower(errMsg) == "unauthorized" {
err = errors.New(commConsts.UnAuthorizedErr.Message)
return
}
return
}
......@@ -102,6 +113,16 @@ func Post(url string, data interface{}) (ret []byte, err error) {
logUtils.Infof(logUtils.ConvertUnicode(ret))
}
jsn, err := simplejson.NewJson(ret)
if err != nil {
return
}
errMsg, _ := jsn.Get("error").String()
if strings.ToLower(errMsg) == "unauthorized" {
err = errors.New(commConsts.UnAuthorizedErr.Message)
return
}
return
}
......
......@@ -15,7 +15,7 @@ func InitCheck() iris.Handler {
return func(ctx *context.Context) {
if dao.GetDB() == nil {
ctx.StopWithJSON(http.StatusOK,
domain.Response{Code: commConsts.NeedInitErr.Code, Msg: i118Utils.Sprintf(commConsts.NeedInitErr.Key)})
domain.Response{Code: commConsts.NeedInitErr.Code, Msg: i118Utils.Sprintf(commConsts.NeedInitErr.Message)})
return
}
......
......@@ -26,7 +26,7 @@ func (c *BaseCtrl) ErrResp(err commConsts.ResponseCode, msg string) (ret domain.
}
func (c *BaseCtrl) ErrMsg(err commConsts.ResponseCode, msg string) (ret string) {
ret = i118Utils.Sprintf(err.Key)
ret = i118Utils.Sprintf(err.Message)
if ret != "" {
ret += ": "
......
......@@ -28,7 +28,7 @@ func (c *ZentaoCtrl) GetProfile(ctx iris.Context) {
data, err := zentaoHelper.GetProfile(workspacePath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.BizErrWorkspaceConfig, err.Error()))
ctx.JSON(c.ErrResp(commConsts.BizErrZentaoRequest, err.Error()))
return
}
......@@ -40,7 +40,12 @@ func (c *ZentaoCtrl) ListSiteAndProduct(ctx iris.Context) {
currProductId, _ := ctx.URLParamInt("currProductId")
sites, currSite, _ := c.SiteService.LoadSites(currSiteId)
products, currProduct, _ := zentaoHelper.LoadSiteProduct(currSite, currProductId)
products, currProduct, err := zentaoHelper.LoadSiteProduct(currSite, currProductId)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.BizErrZentaoRequest, err.Error()))
return
}
data := iris.Map{"sites": sites, "products": products,
"currSite": currSite, "currProduct": currProduct}
......@@ -57,7 +62,7 @@ func (c *ZentaoCtrl) ListProduct(ctx iris.Context) {
data, err := zentaoHelper.ListProduct(workspacePath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.BizErrWorkspaceConfig, err.Error()))
ctx.JSON(c.ErrResp(commConsts.BizErrZentaoRequest, err.Error()))
return
}
......@@ -74,7 +79,7 @@ func (c *ZentaoCtrl) ListModule(ctx iris.Context) {
data, err := zentaoHelper.ListModule(productId, workspacePath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
ctx.JSON(c.ErrResp(commConsts.BizErrZentaoRequest, err.Error()))
return
}
......@@ -91,7 +96,7 @@ func (c *ZentaoCtrl) ListSuite(ctx iris.Context) {
data, err := zentaoHelper.ListSuite(productId, workspacePath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
ctx.JSON(c.ErrResp(commConsts.BizErrZentaoRequest, err.Error()))
return
}
......@@ -108,7 +113,7 @@ func (c *ZentaoCtrl) ListTask(ctx iris.Context) {
data, err := zentaoHelper.ListTask(productId, workspacePath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
ctx.JSON(c.ErrResp(commConsts.BizErrZentaoRequest, err.Error()))
return
}
......@@ -126,7 +131,7 @@ func (c *ZentaoCtrl) GetDataForBugSubmition(ctx iris.Context) {
fields, err := zentaoHelper.GetBugFiledOptions(req, workspacePath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
ctx.JSON(c.ErrResp(commConsts.BizErrZentaoRequest, err.Error()))
return
}
......
......@@ -24,6 +24,8 @@ export const getCurrProductIdBySite = async (currSiteId) => {
return currProductId
}
export const setCurrProductIdBySite = async (currSiteId, currProductId) => {
if (!currSiteId) return
let mp = await getCache(settings.currProductIdBySite);
if (!mp) mp = {}
mp[currSiteId + ''] = currProductId
......
......@@ -62,8 +62,10 @@
<div id="content">
<div class="toolbar">
<a-button @click="extract" type="primary" size="small">{{ t('extract_step') }}</a-button>
<a-button v-if="scriptCode !== ''"
@click="extract" type="primary" size="small">{{ t('extract_step') }}</a-button>
</div>
<div class="editor-panel">
<MonacoEditor
v-if="scriptCode !== ''"
......
......@@ -13,10 +13,10 @@
placeholder="输入关键字搜索" style="width:270px;margin-left: 16px;"/>
</div>
</div>
</template>
<template #extra>
<a-button type="primary" @click="create()">
<a-button v-if="currProduct?.id" type="primary" @click="create()">
<template #icon><PlusCircleOutlined /></template>
{{t('create_workspace')}}
</a-button>
......@@ -86,6 +86,7 @@ interface WorkspaceListSetupData {
pagination: ComputedRef<PaginationConfig>;
columns: any;
currProduct: ComputedRef
models: ComputedRef<any[]>;
loading: Ref<boolean>;
getList: (curr) => void
......@@ -223,6 +224,7 @@ export default defineComponent({
queryParams,
pagination,
currProduct,
columns,
models,
loading,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册