Skip to content

Commit

Permalink
Fix error with creating new devices after login
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtyped committed Nov 28, 2022
1 parent 3eaf882 commit bab2086
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/apis/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,18 @@ func (d *DeviceAPI) HandleGetDevices(w http.ResponseWriter, r *http.Request) {

}

devicesOutput, err := json.Marshal(deviceSlice)
if err != nil {
log.Printf("error marshalling devices: %#v", err)
w.WriteHeader(400)
return
var devicesOutput []byte

if len(deviceSlice) == 0 {
devicesOutput = []byte("[]")
} else {

devicesOutput, err = json.Marshal(deviceSlice)
if err != nil {
log.Printf("error marshalling devices: %#v", err)
w.WriteHeader(400)
return
}
}

w.Write(devicesOutput)
Expand Down

0 comments on commit bab2086

Please sign in to comment.