mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-23 00:57:44 +01:00
Merge pull request #565 from reasonerjt/master
handle DB error to return 409 when creating project
This commit is contained in:
commit
cf23b067a6
@ -42,6 +42,7 @@ type projectReq struct {
|
||||
|
||||
const projectNameMaxLen int = 30
|
||||
const projectNameMinLen int = 4
|
||||
const dupProjectPattern = `Duplicate entry '\w+' for key 'name'`
|
||||
|
||||
// Prepare validates the URL and the user
|
||||
func (p *ProjectAPI) Prepare() {
|
||||
@ -93,9 +94,14 @@ func (p *ProjectAPI) Post() {
|
||||
projectID, err := dao.AddProject(project)
|
||||
if err != nil {
|
||||
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))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user