Skip to content

Commit

Permalink
Merge pull request #810 from ww24/add-report
Browse files Browse the repository at this point in the history
fix(http): add report
  • Loading branch information
ww24 authored Jan 14, 2024
2 parents 6ae6e20 + 056e0d5 commit 848b9e6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions presentation/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ func (h *handler) lineCallback() func(w http.ResponseWriter, r *http.Request) {
events, err := h.bot.EventsFromRequest(r)
if err != nil {
cl.Error("http: failed to parse request", zap.Error(err))
report(r, "http: failed to parse request", err)
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}

if err := h.eventHandler.Handle(ctx, events); err != nil {
cl.Error("http: failed to handle events", zap.Error(err))
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
report(r, "http: failed to handle events", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}

Expand Down Expand Up @@ -141,8 +142,8 @@ func (h *handler) executeScheduler() func(w http.ResponseWriter, r *http.Request

if err := h.eventHandler.HandleSchedule(ctx); err != nil {
cl.Error("http: failed to execute scheduler", zap.Error(err))
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
report(r, "http: failed to execute scheduler", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}

Expand Down Expand Up @@ -199,8 +200,8 @@ func (h *handler) executeReminder() func(w http.ResponseWriter, r *http.Request)

if err := h.eventHandler.HandleReminder(ctx, itemIDJSON); err != nil {
cl.Error("http: failed to execute reminder", zap.Error(err))
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
report(r, "http: failed to execute reminder", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}

Expand Down Expand Up @@ -246,8 +247,8 @@ func (h *handler) serveImage() func(w http.ResponseWriter, r *http.Request) {
}

cl.Error("http: failed to serve image", zap.Error(err))
w.WriteHeader(http.StatusInternalServerError)
report(r, "http: failed to serve image", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
defer rc.Close()
Expand All @@ -262,6 +263,7 @@ func (h *handler) serveImage() func(w http.ResponseWriter, r *http.Request) {
}

cl.Error("http: failed to copy image", zap.Error(err))
report(r, "http: failed to copy image", err)
return
}
}
Expand Down

0 comments on commit 848b9e6

Please sign in to comment.