diff --git a/sqle/api/controller/v1/audit_plan.go b/sqle/api/controller/v1/audit_plan.go index e6bb124d6b..0fa078a48e 100644 --- a/sqle/api/controller/v1/audit_plan.go +++ b/sqle/api/controller/v1/audit_plan.go @@ -218,7 +218,7 @@ func CreateAuditPlan(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errProjectNotExist) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } // check user diff --git a/sqle/api/controller/v1/instance.go b/sqle/api/controller/v1/instance.go index b70ed2f1bb..aecbbe8cf3 100644 --- a/sqle/api/controller/v1/instance.go +++ b/sqle/api/controller/v1/instance.go @@ -204,7 +204,7 @@ func CreateInstance(c echo.Context) error { } if !exist { - return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist"))) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } instance := &model.Instance{ diff --git a/sqle/api/controller/v1/project.go b/sqle/api/controller/v1/project.go index cbe09aae75..e36d6f36ed 100644 --- a/sqle/api/controller/v1/project.go +++ b/sqle/api/controller/v1/project.go @@ -13,7 +13,9 @@ import ( ) var ( - errProjectNotExist = errors.New(errors.DataNotExist, fmt.Errorf("project is not exist")) + errProjectNotExist = func(projectName string) error { + return errors.New(errors.DataNotExist, fmt.Errorf("project [%v] is not exist", projectName)) + } ) type GetProjectReqV1 struct { @@ -118,7 +120,7 @@ func GetProjectDetailV1(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, fmt.Errorf("project not exist")) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } return c.JSON(http.StatusOK, GetProjectDetailResV1{ diff --git a/sqle/api/controller/v1/rule.go b/sqle/api/controller/v1/rule.go index 22b85f2693..1e645946b2 100644 --- a/sqle/api/controller/v1/rule.go +++ b/sqle/api/controller/v1/rule.go @@ -654,7 +654,7 @@ func CreateProjectRuleTemplate(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName))) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } _, exist, err = s.GetGlobalAndProjectRuleTemplateByNameAndProjectId(req.Name, project.ID) @@ -751,7 +751,7 @@ func UpdateProjectRuleTemplate(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName))) + return controller.JSONBaseErrorReq(c,errProjectNotExist(projectName)) } template, exist, err := s.GetGlobalAndProjectRuleTemplateByNameAndProjectId(templateName, project.ID) if err != nil { @@ -856,7 +856,7 @@ func GetProjectRuleTemplate(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName))) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } templateName := c.Param("rule_template_name") template, exist, err := s.GetRuleTemplateDetailByNameAndProjectIds([]uint{project.ID}, templateName) @@ -919,7 +919,7 @@ func DeleteProjectRuleTemplate(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName))) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } templateName := c.Param("rule_template_name") @@ -993,7 +993,7 @@ func GetProjectRuleTemplates(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName))) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize) @@ -1063,7 +1063,7 @@ func CloneProjectRuleTemplate(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName))) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } exist, err = s.IsRuleTemplateExistFromAnyProject(req.Name) if err != nil { @@ -1152,7 +1152,7 @@ func GetProjectRuleTemplateTips(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName))) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } return getRuleTemplateTips(c, project.ID, req.FilterDBType) diff --git a/sqle/api/controller/v1/sql_whitelist.go b/sqle/api/controller/v1/sql_whitelist.go index 61c64a3807..aeda6d82c3 100644 --- a/sqle/api/controller/v1/sql_whitelist.go +++ b/sqle/api/controller/v1/sql_whitelist.go @@ -47,7 +47,7 @@ func CreateAuditWhitelist(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errProjectNotExist) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } sqlWhitelist := &model.SqlWhitelist{ diff --git a/sqle/api/controller/v1/user.go b/sqle/api/controller/v1/user.go index 24f3727182..02303882da 100644 --- a/sqle/api/controller/v1/user.go +++ b/sqle/api/controller/v1/user.go @@ -802,7 +802,7 @@ func checkMemberCanDelete(userName, projectName string) error { return err } if !exist { - return errors.New(errors.DataNotExist, fmt.Errorf("project not exist")) + return errProjectNotExist(projectName) } if len(project.Managers) == 1 && project.Managers[0].ID == user.ID { diff --git a/sqle/api/controller/v1/workflow.go b/sqle/api/controller/v1/workflow.go index 7a4173442f..afb985c32b 100644 --- a/sqle/api/controller/v1/workflow.go +++ b/sqle/api/controller/v1/workflow.go @@ -74,7 +74,7 @@ func GetWorkflowTemplate(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errProjectNotExist) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } template, exist, err := s.GetWorkflowTemplateById(project.WorkflowTemplateId) @@ -201,7 +201,7 @@ func UpdateWorkflowTemplate(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errProjectNotExist) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } userName := controller.GetUserName(c) @@ -344,7 +344,7 @@ func ApproveWorkflow(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errProjectNotExist) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } userName := controller.GetUserName(c) @@ -446,7 +446,7 @@ func RejectWorkflow(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errProjectNotExist) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } workflowName := c.Param("workflow_name") @@ -533,7 +533,7 @@ func CancelWorkflow(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errProjectNotExist) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } workflowName := c.Param("workflow_name") @@ -949,7 +949,7 @@ func CreateWorkflowV1(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errProjectNotExist) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } user, err := controller.GetCurrentUser(c) @@ -1230,7 +1230,7 @@ func GetWorkflowsV1(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } if !exist { - return controller.JSONBaseErrorReq(c, errProjectNotExist) + return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName)) } user, err := controller.GetCurrentUser(c)