Skip to content

Commit

Permalink
fix segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed May 13, 2024
1 parent 86516d5 commit 4c52b97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ func main() {
slogecho.AddCustomAttributes(c, slog.String("foo", "bar"))
return c.String(http.StatusOK, "Hello, World!")
})
e.GET("/error", func(c echo.Context) error {
e.GET("/error1", func(c echo.Context) error {
return echo.
NewHTTPError(http.StatusInternalServerError, "A simulated error").
WithInternal(errors.New("A simulated internal error"))
})
e.GET("/error2", func(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "A simulated error")
})
e.GET("/error3", func(c echo.Context) error {
return errors.New("A simulated error")
})

// Start server
e.Logger.Fatal(e.Start(":4242"))
Expand Down
5 changes: 4 additions & 1 deletion middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,11 @@ func NewWithConfig(logger *slog.Logger, config Config) echo.MiddlewareFunc {
"message": httpErr.Message,
"internal": httpErr.Internal,
}),
slog.String("internal", httpErr.Internal.Error()),
)

if httpErr.Internal != nil {
attributes = append(attributes, slog.String("internal", httpErr.Internal.Error()))
}
}

logger.LogAttrs(c.Request().Context(), level, msg, attributes...)
Expand Down

0 comments on commit 4c52b97

Please sign in to comment.