This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 688d8db3 fix: return 404 if record not found (#3859)
688d8db3 is described below
commit 688d8db30f8e862c598663f4308ba84d6fbb60a4
Author: mindlesscloud <[email protected]>
AuthorDate: Tue Dec 6 15:04:57 2022 +0800
fix: return 404 if record not found (#3859)
* fix: return 404 if record not found
* refactor: define a new variable errors.ErrRecordNotFound
* refactor: revert last commit
---
plugins/github/api/scope.go | 4 ++++
plugins/gitlab/api/scope.go | 4 ++++
plugins/jenkins/api/scope.go | 4 ++++
plugins/jira/api/scope.go | 4 ++++
4 files changed, 16 insertions(+)
diff --git a/plugins/github/api/scope.go b/plugins/github/api/scope.go
index 40322387..29e27ac9 100644
--- a/plugins/github/api/scope.go
+++ b/plugins/github/api/scope.go
@@ -28,6 +28,7 @@ import (
"github.com/apache/incubator-devlake/plugins/github/models"
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/mitchellh/mapstructure"
+ "gorm.io/gorm"
)
type apiRepo struct {
@@ -183,6 +184,9 @@ func GetScope(input *core.ApiResourceInput)
(*core.ApiResourceOutput, errors.Err
return nil, errors.BadInput.New("invalid path params")
}
err := basicRes.GetDal().First(&repo, dal.Where("connection_id = ? AND
github_id = ?", connectionId, repoId))
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ return nil, errors.NotFound.New("record not found")
+ }
if err != nil {
return nil, err
}
diff --git a/plugins/gitlab/api/scope.go b/plugins/gitlab/api/scope.go
index afda4a11..13f3b614 100644
--- a/plugins/gitlab/api/scope.go
+++ b/plugins/gitlab/api/scope.go
@@ -28,6 +28,7 @@ import (
"github.com/apache/incubator-devlake/plugins/gitlab/models"
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/mitchellh/mapstructure"
+ "gorm.io/gorm"
)
type apiProject struct {
@@ -183,6 +184,9 @@ func GetScope(input *core.ApiResourceInput)
(*core.ApiResourceOutput, errors.Err
return nil, errors.BadInput.New("invalid path params")
}
err := BasicRes.GetDal().First(&project, dal.Where("connection_id = ?
AND gitlab_id = ?", connectionId, projectId))
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ return nil, errors.NotFound.New("record not found")
+ }
if err != nil {
return nil, err
}
diff --git a/plugins/jenkins/api/scope.go b/plugins/jenkins/api/scope.go
index 9eedacf2..859aa25b 100644
--- a/plugins/jenkins/api/scope.go
+++ b/plugins/jenkins/api/scope.go
@@ -27,6 +27,7 @@ import (
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/apache/incubator-devlake/plugins/jenkins/models"
"github.com/mitchellh/mapstructure"
+ "gorm.io/gorm"
)
type apiJob struct {
@@ -174,6 +175,9 @@ func GetScope(input *core.ApiResourceInput)
(*core.ApiResourceOutput, errors.Err
return nil, err
}
err = BasicRes.GetDal().First(&job, dal.Where("connection_id = ? AND
full_name = ?", connectionId, fullName))
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ return nil, errors.NotFound.New("record not found")
+ }
if err != nil {
return nil, err
}
diff --git a/plugins/jira/api/scope.go b/plugins/jira/api/scope.go
index faad1394..5de05977 100644
--- a/plugins/jira/api/scope.go
+++ b/plugins/jira/api/scope.go
@@ -27,6 +27,7 @@ import (
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/apache/incubator-devlake/plugins/jira/models"
"github.com/mitchellh/mapstructure"
+ "gorm.io/gorm"
)
type apiBoard struct {
@@ -179,6 +180,9 @@ func GetScope(input *core.ApiResourceInput)
(*core.ApiResourceOutput, errors.Err
return nil, errors.BadInput.New("invalid path params")
}
err := basicRes.GetDal().First(&board, dal.Where("connection_id = ? AND
board_id = ?", connectionId, boardId))
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ return nil, errors.NotFound.New("record not found")
+ }
if err != nil {
return nil, err
}