aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Shyi <chrisshyi13@gmail.com>2020-10-12 21:44:56 +0800
committerGitHub <noreply@github.com>2020-10-12 14:44:56 +0100
commitc752ccee6425091cf17c98029f039f3fe66552b4 (patch)
tree1fd499117672e13c6323f433577ad98f1d4a197d
parent0e4f663126dbd39266e56203cca48b8a5aa85ee6 (diff)
downloadgitea-c752ccee6425091cf17c98029f039f3fe66552b4.tar.gz
gitea-c752ccee6425091cf17c98029f039f3fe66552b4.zip
Improve error feedback for duplicate deploy keys (#13112)
Instead of a generic HTTP 500 error page, a flash message is rendered with the deploy key page template to inform the user that a key with the intended title already exists. Fixes #13110
-rw-r--r--models/error.go2
-rw-r--r--routers/api/v1/repo/key.go2
-rw-r--r--routers/repo/setting.go3
3 files changed, 6 insertions, 1 deletions
diff --git a/models/error.go b/models/error.go
index 1cab19aafd..364924c996 100644
--- a/models/error.go
+++ b/models/error.go
@@ -547,7 +547,7 @@ func IsErrDeployKeyNameAlreadyUsed(err error) bool {
}
func (err ErrDeployKeyNameAlreadyUsed) Error() string {
- return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
+ return fmt.Sprintf("public key with name already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
}
// _____ ___________ __
diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go
index 5d63a25d64..3d16ae6d40 100644
--- a/routers/api/v1/repo/key.go
+++ b/routers/api/v1/repo/key.go
@@ -177,6 +177,8 @@ func HandleAddKeyError(ctx *context.APIContext, err error) {
ctx.Error(http.StatusUnprocessableEntity, "", "Key content has been used as non-deploy key")
case models.IsErrKeyNameAlreadyUsed(err):
ctx.Error(http.StatusUnprocessableEntity, "", "Key title has been used")
+ case models.IsErrDeployKeyNameAlreadyUsed(err):
+ ctx.Error(http.StatusUnprocessableEntity, "", "A key with the same name already exists")
default:
ctx.Error(http.StatusInternalServerError, "AddKey", err)
}
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index ca222375fb..1b75522958 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -885,6 +885,9 @@ func DeployKeysPost(ctx *context.Context, form auth.AddKeyForm) {
case models.IsErrKeyNameAlreadyUsed(err):
ctx.Data["Err_Title"] = true
ctx.RenderWithErr(ctx.Tr("repo.settings.key_name_used"), tplDeployKeys, &form)
+ case models.IsErrDeployKeyNameAlreadyUsed(err):
+ ctx.Data["Err_Title"] = true
+ ctx.RenderWithErr(ctx.Tr("repo.settings.key_name_used"), tplDeployKeys, &form)
default:
ctx.ServerError("AddDeployKey", err)
}