some input validation

This commit is contained in:
Erik Winter 2024-09-09 07:41:34 +02:00
parent 32bed5acc8
commit fdbefeffe2
1 changed files with 12 additions and 0 deletions

View File

@ -92,6 +92,18 @@ func (s *Server) SyncPost(w http.ResponseWriter, r *http.Request) {
}
for _, item := range items {
if item.ID == "" {
http.Error(w, `{"error":"item without an id"}`, http.StatusBadRequest)
return
}
if item.Kind == "" {
http.Error(w, fmt.Sprintf(`{"error":"item %s does not have a kind"}`, item.ID), http.StatusBadRequest)
return
}
if item.Body == "" {
http.Error(w, fmt.Sprintf(`{"error":"item %s does not have a body"}`, item.ID), http.StatusBadRequest)
return
}
item.Updated = time.Now()
if err := s.syncer.Update(item); err != nil {
http.Error(w, fmtError(err), http.StatusInternalServerError)