8000 fix(site): show error on duplicate template rename attempt by ethanndickson · Pull Request #15348 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading 8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(site): show error on duplicate template rename attempt
  • Loading branch information
ethanndickson committed Nov 5, 2024
commit c0631b01546b8aae94310d82aca8b9c0f005d7d9
12 changes: 11 additions & 1 deletion coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { API } from "api/api";
import { getErrorMessage } from "api/errors";
import { templateByNameKey } from "api/queries/templates";
import type { UpdateTemplateMeta } from "api/typesGenerated";
import { displaySuccess } from "components/GlobalSnackbar/utils";
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils";
import { useDashboard } from "modules/dashboard/useDashboard";
import { linkToTemplate, useLinks } from "modules/navigation";
import type { FC } from "react";
Expand Down Expand Up @@ -51,6 +52,9 @@ export const TemplateSettingsPage: FC = () => {
displaySuccess("Template updated successfully");
navigate(getLink(linkToTemplate(data.organization_name, data.name)));
},
onError: (error) => {
displayError(getErrorMessage(error, "Failed to update template"));
},
},
);

Expand Down
0