Config: 404 for status of deleted device (#31031)
This commit is contained in:
parent
eed0649eaa
commit
206475271c
2 changed files with 8 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue