Browse Source

lib/api: Missing error handling in config handler (#8463)

Jakob Borg 3 years ago
parent
commit
8b4bd43306
1 changed files with 8 additions and 0 deletions
  1. 8 0
      lib/api/confighandler.go

+ 8 - 0
lib/api/confighandler.go

@@ -63,6 +63,10 @@ func (c *configMuxBuilder) registerFolders(path string) {
 
 	c.HandlerFunc(http.MethodPut, path, func(w http.ResponseWriter, r *http.Request) {
 		data, err := unmarshalToRawMessages(r.Body)
+		if err != nil {
+			http.Error(w, err.Error(), http.StatusBadRequest)
+			return
+		}
 		folders := make([]config.FolderConfiguration, len(data))
 		defaultFolder := c.cfg.DefaultFolder()
 		for i, bs := range data {
@@ -94,6 +98,10 @@ func (c *configMuxBuilder) registerDevices(path string) {
 
 	c.HandlerFunc(http.MethodPut, path, func(w http.ResponseWriter, r *http.Request) {
 		data, err := unmarshalToRawMessages(r.Body)
+		if err != nil {
+			http.Error(w, err.Error(), http.StatusBadRequest)
+			return
+		}
 		devices := make([]config.DeviceConfiguration, len(data))
 		defaultDevice := c.cfg.DefaultDevice()
 		for i, bs := range data {