Fix validation and add error message

pull/2972/head
ssbkang 2019-06-27 22:19:09 +12:00
parent 1a387228b0
commit 1732548e59
2 changed files with 10 additions and 4 deletions

View File

@ -115,3 +115,8 @@ const (
ErrWebhookAlreadyExists = Error("A webhook for this resource already exists")
ErrUnsupportedWebhookType = Error("Webhooks for this resource are not currently supported")
)
// Deploymentkey errors
const (
ErrDeploymentkeyAlreadyExists = Error("A deployment key for this resource already exists")
)

View File

@ -29,10 +29,11 @@ func (handler *Handler) deploymentkeyCreate(w http.ResponseWriter, r *http.Reque
}
deploymentkey, err := handler.DeploymentKeyService.DeploymentKeyByName(payload.Name)
if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a deployment key with the specified identifier inside the database", err}
} else if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a deployment key with the specified identifier inside the database", err}
if err != nil && err != portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusInternalServerError, "An error occurred retrieving deploymentkey from the database", err}
}
if deploymentkey != nil {
return &httperror.HandlerError{http.StatusConflict, "A deploymentkey for this resource already exists", portainer.ErrDeploymentkeyAlreadyExists}
}
// Add a function to call and create public key and private key