refactor: code cleanup

This commit is contained in:
Marvin Zhang
2024-10-20 17:22:35 +08:00
parent 418af7c215
commit 3c53fde7e2
25 changed files with 21 additions and 195 deletions

View File

@@ -1,7 +1,7 @@
package controllers
import (
"github.com/crawlab-team/crawlab/core/errors"
"errors"
models2 "github.com/crawlab-team/crawlab/core/models/models/v2"
"github.com/crawlab-team/crawlab/core/models/service"
"github.com/crawlab-team/crawlab/db/mongo"
@@ -73,7 +73,7 @@ func GetProjectList(c *gin.Context) {
for _, s := range spiders {
_, ok := cache[s.ProjectId]
if !ok {
HandleErrorInternalServerError(c, errors.ErrorControllerMissingInCache)
HandleErrorInternalServerError(c, errors.New("project id not found"))
return
}
cache[s.ProjectId]++

View File

@@ -1,7 +1,7 @@
package controllers
import (
"github.com/crawlab-team/crawlab/core/errors"
errors2 "errors"
"github.com/crawlab-team/crawlab/core/models/models/v2"
"github.com/crawlab-team/crawlab/core/models/service"
"github.com/crawlab-team/crawlab/core/schedule"
@@ -56,7 +56,7 @@ func PutScheduleById(c *gin.Context) {
return
}
if s.Id != id {
HandleErrorBadRequest(c, errors.ErrorHttpBadRequest)
HandleErrorBadRequest(c, errors2.New("id in path does not match id in body"))
return
}

View File

@@ -2,9 +2,9 @@ package controllers
import (
"encoding/json"
errors2 "errors"
"github.com/crawlab-team/crawlab/core/constants"
"github.com/crawlab-team/crawlab/core/entity"
"github.com/crawlab-team/crawlab/core/errors"
"github.com/crawlab-team/crawlab/core/utils"
"github.com/crawlab-team/crawlab/db/generic"
"github.com/gin-gonic/gin"
@@ -111,7 +111,7 @@ func GetFilterAll(c *gin.Context) (res bool, err error) {
case "FALSE":
return false, nil
default:
return false, errors.ErrorFilterInvalidOperation
return false, errors2.New("invalid value")
}
}