diff --git a/middleware.go b/middleware.go index 819b6c4..106f10a 100644 --- a/middleware.go +++ b/middleware.go @@ -215,10 +215,18 @@ func NewWithConfig(logger *slog.Logger, config Config) echo.MiddlewareFunc { msg := "Incoming request" if status >= http.StatusInternalServerError { level = config.ServerErrorLevel - msg = err.Error() + if err != nil { + msg = err.Error() + } else { + msg = http.StatusText(status) + } } else if status >= http.StatusBadRequest && status < http.StatusInternalServerError { level = config.ClientErrorLevel - msg = err.Error() + if err != nil { + msg = err.Error() + } else { + msg = http.StatusText(status) + } } logger.LogAttrs(c.Request().Context(), level, msg, attributes...)