Skip to content

Commit

Permalink
chore: cleanup error handler so 404 errors are not logged _as_ errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jippi committed Aug 30, 2024
1 parent 750d43b commit b01bf9b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/gitlab_server_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import (
"context"
"log/slog"
"net/http"
"strings"

slogctx "github.com/veqryn/slog-context"
)

func errHandler(ctx context.Context, w http.ResponseWriter, code int, err error) {
slogctx.Error(ctx, "Server response", slog.Int("response_code", code), slog.Any("response_message", err))
// Treat 404 errors as informational instead of actual errors
if strings.Contains(err.Error(), "404 Not Found") {
slogctx.Info(ctx, "Server response", slog.Int("response_code", code), slog.Any("response_message", err))
} else {
slogctx.Error(ctx, "Server response", slog.Int("response_code", code), slog.Any("response_message", err))
}

w.WriteHeader(code)
w.Write([]byte(err.Error()))
Expand Down

0 comments on commit b01bf9b

Please sign in to comment.