From ceb53970a18e956fbeebd250e7d64f894f1af816 Mon Sep 17 00:00:00 2001 From: "J. David Lee" Date: Mon, 10 Jun 2019 21:36:28 +0200 Subject: [PATCH] Code cleanup --- report-handler.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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) } }