Browse Source

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
tags/v1.13.0-rc1
Chris Shyi GitHub 5 years ago
parent
commit
6225ba86b1
3 changed files with 6 additions and 1 deletions
  1. +1
    -1
      models/error.go
  2. +2
    -0
      routers/api/v1/repo/key.go
  3. +3
    -0
      routers/repo/setting.go

+ 1
- 1
models/error.go View File

@@ -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)
}

// _____ ___________ __


+ 2
- 0
routers/api/v1/repo/key.go View File

@@ -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)
}


+ 3
- 0
routers/repo/setting.go View File

@@ -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)
}


Loading…
Cancel
Save