From 7019f5b938383b5964d3cb946bb9f2a016b51d9d Mon Sep 17 00:00:00 2001 From: j2gg0s Date: Mon, 14 Oct 2024 20:01:09 +0800 Subject: [PATCH] log: log unexpected error and ignore healthcheck (#196) --- failure/http.go | 1 + server/http.go | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/failure/http.go b/failure/http.go index 44b0cdc0..9bee68d9 100644 --- a/failure/http.go +++ b/failure/http.go @@ -30,6 +30,7 @@ func Handle(h Handler) gin.HandlerFunc { c.String(http.StatusBadRequest, cerr.Error()) } + c.Error(err) panic(err) } } diff --git a/server/http.go b/server/http.go index 6e765b38..e1250a93 100644 --- a/server/http.go +++ b/server/http.go @@ -70,13 +70,16 @@ func (s *HTTPServer) Init() error { } ) + router.GET("/healthcheck", handlers.healthcheck(time.Now().UTC())) + + router.Use(middleware.NewLogger(s.processor.Logger)) + if s.config.Debug { router.Use(gin.Recovery()) } else { router.Use(middleware.Recover) } - router.Use(middleware.NewLogger(s.processor.Logger)) router.Use(middleware.Metrics) if s.config.Sentry != nil { @@ -112,8 +115,6 @@ func (s *HTTPServer) Init() error { })) } - router.GET("/healthcheck", handlers.healthcheck(time.Now().UTC())) - restrictIPAddresses := middleware.RestrictIPAddresses(s.config.Options.AllowedIPAddresses) if s.config.Options.EnableStats {