Config: 404 for status of deleted device (#31031)

This commit is contained in:
Michael Geers 2026-06-19 18:57:12 +02:00 • committed by GitHub
parent eed0649eaa
commit 206475271c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View file

@ -272,6 +272,10 @@ func deviceStatusHandler(w http.ResponseWriter, r *http.Request) {
}
if err != nil {
if errors.Is(err, config.ErrNotFound) {
jsonError(w, http.StatusNotFound, err)
return
}
jsonError(w, http.StatusBadRequest, err)
return
}

View file

@ -19,6 +19,8 @@ const (
OpDelete Operation = "del"
)
var ErrNotFound = errors.New("not found")
func (cp *handler[T]) Subscribe(fn func(Operation, Device[T])) {
if err := bus.Subscribe(cp.topic, fn); err != nil {
panic(err)
@ -69,7 +71,7 @@ func (cp *handler[T]) Delete(name string) error {
}
cp.mu.Unlock()
return fmt.Errorf("not found: %s", name)
return fmt.Errorf("%w: %s", ErrNotFound, name)
}
// ByName provides device by name
@ -83,5 +85,5 @@ func (cp *handler[T]) ByName(name string) (Device[T], error) {
}
}
return nil, fmt.Errorf("not found: %s", name)
return nil, fmt.Errorf("%w: %s", ErrNotFound, name)
}