Skip to content

Commit

Permalink
fix(#979): GetHubFromContext may crash instead of returning nil
Browse files Browse the repository at this point in the history
  • Loading branch information
kohnalex committed Feb 22, 2024
1 parent 668510e commit 2d0926f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fibersentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func New(config ...Config) fiber.Handler {
return func(c *fiber.Ctx) error {
// Convert fiber request to http request
r, err := adaptor.ConvertRequest(c, true)

if err != nil {
return err
}
Expand Down Expand Up @@ -54,5 +53,9 @@ func New(config ...Config) fiber.Handler {
}

func GetHubFromContext(ctx *fiber.Ctx) *sentry.Hub {
return ctx.Locals(hubKey).(*sentry.Hub)
hub, ok := ctx.Locals(hubKey).(*sentry.Hub)
if !ok {
return nil
}
return hub
}

0 comments on commit 2d0926f

Please # to comment.