mirror of
https://github.com/goharbor/harbor
synced 2025-04-27 23:46:24 +00:00
handle DB error to return 409 when creating project
This commit is contained in:
parent
cc41aa76e0
commit
236a54f9bd
@ -42,6 +42,7 @@ type projectReq struct {
|
|||||||
|
|
||||||
const projectNameMaxLen int = 30
|
const projectNameMaxLen int = 30
|
||||||
const projectNameMinLen int = 4
|
const projectNameMinLen int = 4
|
||||||
|
const dupProjectPattern = `Duplicate entry '\w+' for key 'name'`
|
||||||
|
|
||||||
// Prepare validates the URL and the user
|
// Prepare validates the URL and the user
|
||||||
func (p *ProjectAPI) Prepare() {
|
func (p *ProjectAPI) Prepare() {
|
||||||
@ -93,9 +94,14 @@ func (p *ProjectAPI) Post() {
|
|||||||
projectID, err := dao.AddProject(project)
|
projectID, err := dao.AddProject(project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to add project, error: %v", err)
|
log.Errorf("Failed to add project, error: %v", err)
|
||||||
p.RenderError(http.StatusInternalServerError, "Failed to add project")
|
dup, _ := regexp.MatchString(dupProjectPattern, err.Error())
|
||||||
|
if dup {
|
||||||
|
p.RenderError(http.StatusConflict, "")
|
||||||
|
} else {
|
||||||
|
p.RenderError(http.StatusInternalServerError, "Failed to add project")
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Redirect(http.StatusCreated, strconv.FormatInt(projectID, 10))
|
p.Redirect(http.StatusCreated, strconv.FormatInt(projectID, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user