Skip to content

Commit

Permalink
feat: logging before error response
Browse files Browse the repository at this point in the history
  • Loading branch information
kyong0612 committed Jan 2, 2024
1 parent eecf963 commit 3526a8f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions handler/line-webhook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"log/slog"
"net/http"

"github.com/kyong0612/fitness-supporter/infra/line"
Expand All @@ -24,6 +25,7 @@ func PostLINEWebhook(w http.ResponseWriter, r *http.Request) {

line, err := line.NewClient()
if err != nil {
slog.ErrorContext(ctx, "failed to create line client", slog.Any("err", err))
http.Error(w, err.Error(), http.StatusInternalServerError)

return
Expand All @@ -32,12 +34,16 @@ func PostLINEWebhook(w http.ResponseWriter, r *http.Request) {
for _, event := range events {
resp, err := line.ReplyMessage(ctx, event.ReplyToken, []string{event.Content})
if err != nil {
slog.ErrorContext(ctx, "failed to reply message",
slog.Any("err", err),
)
http.Error(w, err.Error(), http.StatusInternalServerError)

return
}

if err := resp.Body.Close(); err != nil {
slog.ErrorContext(ctx, "failed to close response body", slog.Any("err", err))
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
Expand Down

0 comments on commit 3526a8f

Please sign in to comment.