diff --git a/report-handler.go b/report-handler.go index 6912955..7023bca 100644 --- a/report-handler.go +++ b/report-handler.go @@ -19,10 +19,15 @@ func handleReport(w http.ResponseWriter, r *http.Request) { switch action { case "ping": - _ = db.SourceUpdateLastSeenAt(src.SourceID) - w.WriteHeader(http.StatusOK) + if err = db.SourceUpdateLastSeenAt(src.SourceID); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } else { + w.WriteHeader(http.StatusOK) + } case "log": + _ = db.SourceUpdateLastSeenAt(src.SourceID) + text := r.Form.Get("text") _ = db.LogInsert(Entry{ SourceID: src.SourceID, @@ -32,6 +37,8 @@ func handleReport(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) case "alert": + _ = db.SourceUpdateLastSeenAt(src.SourceID) + text := r.Form.Get("text") _ = db.LogInsert(Entry{ SourceID: src.SourceID, @@ -40,5 +47,8 @@ func handleReport(w http.ResponseWriter, r *http.Request) { }) runAlertAction(src.AlertAction, src.Name, text) w.WriteHeader(http.StatusOK) + + default: + http.Error(w, "Unknown action: "+action, http.StatusBadRequest) } }