fix(site): show error on duplicate template rename attempt (#15348)

Fixes #15311.
This commit is contained in:
Ethan
2024-11-06 01:18:38 +11:00
committed by GitHub
parent 2d00b50eb6
commit 3c60dc3bb5
4 changed files with 70 additions and 3 deletions
+11 -1
View File
@@ -841,7 +841,17 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
return nil
}, nil)
if err != nil {
httpapi.InternalServerError(rw, err)
if database.IsUniqueViolation(err, database.UniqueTemplatesOrganizationIDNameIndex) {
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
Message: fmt.Sprintf("Template with name %q already exists.", req.Name),
Validations: []codersdk.ValidationError{{
Field: "name",
Detail: "This value is already in use and should be unique.",
}},
})
} else {
httpapi.InternalServerError(rw, err)
}
return
}