From 1205207cb78992660b1766f3059ffab5cf124eed Mon Sep 17 00:00:00 2001 From: Fang Jie Date: Wed, 5 Jun 2024 01:30:16 +0800 Subject: [PATCH] fix: httpErr always non-nil (#33) --- middleware.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/middleware.go b/middleware.go index 1534357..5657c2b 100644 --- a/middleware.go +++ b/middleware.go @@ -3,12 +3,11 @@ package slogecho import ( "context" "errors" + "log/slog" "net/http" "strings" "time" - "log/slog" - "github.com/labstack/echo/v4" "github.com/samber/lo" "go.opentelemetry.io/otel/trace" @@ -141,7 +140,7 @@ func NewWithConfig(logger *slog.Logger, config Config) echo.MiddlewareFunc { ip := c.RealIP() referer := c.Request().Referer() - httpErr := new(echo.HTTPError) + var httpErr *echo.HTTPError if err != nil && errors.As(err, &httpErr) { status = httpErr.Code if msg, ok := httpErr.Message.(string); ok {