fix(iot): 409 различает конфликт name vs device_id (ревью)
store.Create классифицирует 23505 по имени constraint: (namespace,device_id) → ErrDeviceIDExists, иначе ErrAlreadyExists. Handler отдаёт разные 409-сообщения. Помогает Terraform понять, какое поле конфликтует.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user