fix(iot): 409 различает конфликт name vs device_id (ревью)

store.Create классифицирует 23505 по имени constraint: (namespace,device_id) →
ErrDeviceIDExists, иначе ErrAlreadyExists. Handler отдаёт разные 409-сообщения.
Помогает Terraform понять, какое поле конфликтует.
This commit is contained in:
Repinoid
2026-10-10 19:21:47 +03:00
parent 3b7c8a0a63
commit 3a73207abd
3 changed files with 18 additions and 0 deletions
+4
View File
@@ -215,6 +215,10 @@ func (h *Handler) CreateIoTDevice(w http.ResponseWriter, r *http.Request) {
}
if err := h.Devices.Create(r.Context(), device); err != nil {
if errors.Is(err, store.ErrDeviceIDExists) {
writeJSON(w, http.StatusConflict, errResp("device_id already exists in this namespace"))
return
}
if errors.Is(err, store.ErrAlreadyExists) {
writeJSON(w, http.StatusConflict, errResp("iot device already exists"))
return