This is an automated email from the ASF dual-hosted git repository.
klesh 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 9ca93d9b fix: more friendly error message for duplicated connection
name (#3268)
9ca93d9b is described below
commit 9ca93d9bd79339ced9f8127bcbc79b735f7fbf69
Author: mindlesscloud <[email protected]>
AuthorDate: Fri Sep 30 11:29:04 2022 +0800
fix: more friendly error message for duplicated connection name (#3268)
* fix: more friendly error message
* refactor: remove from the error message
* fix: improve error message
---
api/router.go | 5 ++---
api/shared/api_output.go | 3 ++-
plugins/helper/connection.go | 4 ++++
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/api/router.go b/api/router.go
index 97fd3d96..4ad4e98d 100644
--- a/api/router.go
+++ b/api/router.go
@@ -19,7 +19,6 @@ package api
import (
"fmt"
- "github.com/apache/incubator-devlake/errors"
"net/http"
"strings"
@@ -96,14 +95,14 @@ func handlePluginCall(pluginName string, handler
core.ApiResourceHandler) func(c
} else {
err = c.ShouldBindJSON(&input.Body)
if err != nil && err.Error() != "EOF" {
- shared.ApiOutputError(c,
errors.Default.Wrap(err, fmt.Sprintf("could not bind input of plugin %s to
JSON", pluginName)))
+ shared.ApiOutputError(c, err)
return
}
}
}
output, err := handler(input)
if err != nil {
- shared.ApiOutputError(c, errors.BadInput.Wrap(err,
fmt.Sprintf("error executing the requested resource for plugin %s",
pluginName)))
+ shared.ApiOutputError(c, err)
} else if output != nil {
status := output.Status
if status < http.StatusContinue {
diff --git a/api/shared/api_output.go b/api/shared/api_output.go
index cd0ffc6d..188b82f0 100644
--- a/api/shared/api_output.go
+++ b/api/shared/api_output.go
@@ -19,11 +19,12 @@ package shared
import (
"fmt"
+ "net/http"
+
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/logger"
"github.com/apache/incubator-devlake/models"
"github.com/gin-gonic/gin"
- "net/http"
)
const BadRequestBody = "bad request body format"
diff --git a/plugins/helper/connection.go b/plugins/helper/connection.go
index 74f91434..703409c9 100644
--- a/plugins/helper/connection.go
+++ b/plugins/helper/connection.go
@@ -23,6 +23,7 @@ import (
"github.com/apache/incubator-devlake/errors"
"reflect"
"strconv"
+ "strings"
"github.com/apache/incubator-devlake/models/common"
"github.com/apache/incubator-devlake/plugins/core"
@@ -164,6 +165,9 @@ func (c *ConnectionApiHelper) save(connection interface{})
errors.Error {
err := c.db.CreateOrUpdate(connection)
if err != nil {
+ if strings.Contains(err.Error(), "duplicate") {
+ return errors.BadInput.Wrap(err, "duplicated Connection
Name")
+ }
return err
}