Skip to content

Commit

Permalink
feat: readable logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kyong0612 committed Jan 2, 2024
1 parent 42649f7 commit 8cbfbfc
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions infra/line/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ type MessageEvent struct {
}

func ParseWebhookRequest(ctx context.Context, req *http.Request) ([]MessageEvent, error) {
cb, err := webhook.ParseRequest(
config.Get().LINEChannelToken,
req,
)
if err != nil {
return nil, errors.Wrap(err, "failed to parse webhook request")
}

dump, err := httputil.DumpRequest(req, true)
if err != nil {
return nil, errors.Wrap(err, "failed to dump request")
Expand All @@ -41,11 +33,19 @@ func ParseWebhookRequest(ctx context.Context, req *http.Request) ([]MessageEvent
slog.InfoContext(
ctx,
"webhook request parsed",
slog.Group(
"request", slog.String("body", string(dump)),
),
slog.String("dump", string(dump)),
)

cb, err := webhook.ParseRequest(
config.Get().LINEChannelToken,
req,
)
if err != nil {
slog.ErrorContext(ctx, "failed to parse webhook request", err)
// NOTE: healthcheckを通過させるために、エラー時はnilを返す
return nil, nil
}

result := make([]MessageEvent, 0, len(cb.Events))

for _, event := range cb.Events {
Expand Down

0 comments on commit 8cbfbfc

Please sign in to comment.