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 d9751485f fix(webhook): rollback database when webhook's name is same
(#7778)
d9751485f is described below
commit d9751485fc8774dc301743e0c0ba6ab9e2bb4d34
Author: Lynwee <[email protected]>
AuthorDate: Wed Jul 24 16:24:29 2024 +0800
fix(webhook): rollback database when webhook's name is same (#7778)
* fix(webhook): rollback database when webhook's name is same
* fix(webhook): update error messages
---
backend/plugins/webhook/api/connection.go | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/backend/plugins/webhook/api/connection.go
b/backend/plugins/webhook/api/connection.go
index f3c9e9116..acb8a76a5 100644
--- a/backend/plugins/webhook/api/connection.go
+++ b/backend/plugins/webhook/api/connection.go
@@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"strconv"
+ "strings"
"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
@@ -44,6 +45,12 @@ func PostConnections(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput,
tx := basicRes.GetDal().Begin()
err := connectionHelper.CreateWithTx(tx, connection, input)
if err != nil {
+ if err := tx.Rollback(); err != nil {
+ logger.Error(err, "transaction Rollback")
+ }
+ if strings.Contains(err.Error(), "the connection name already
exists (400)") {
+ return nil, errors.BadInput.New(fmt.Sprintf("A webhook
with name %s already exists.", connection.Name))
+ }
return nil, err
}
logger.Info("connection: %+v", connection)