Skip to content

Commit

Permalink
Plugs the Error Handler into the Gin adaptor
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Dec 20, 2024
1 parent 6ecde1f commit d6849d5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions extra/fuegogin/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Post[T, B any](engine *fuego.Engine, ginRouter gin.IRouter, path string, ha

func handleFuego[T, B any](engine *fuego.Engine, ginRouter gin.IRouter, method, path string, fuegoHandler func(c fuego.ContextWithBody[B]) (T, error), options ...func(*fuego.BaseRoute)) *fuego.Route[T, B] {
baseRoute := fuego.NewBaseRoute(method, path, fuegoHandler, engine.OpenAPI, options...)
return handle(engine, ginRouter, &fuego.Route[T, B]{BaseRoute: baseRoute}, GinHandler(fuegoHandler))
return handle(engine, ginRouter, &fuego.Route[T, B]{BaseRoute: baseRoute}, GinHandler(engine, fuegoHandler))
}

func handleGin(engine *fuego.Engine, ginRouter gin.IRouter, method, path string, ginHandler gin.HandlerFunc, options ...func(*fuego.BaseRoute)) *fuego.Route[any, any] {
Expand All @@ -52,7 +52,7 @@ func handle[T, B any](engine *fuego.Engine, ginRouter gin.IRouter, route *fuego.
}

// Convert a Fuego handler to a Gin handler.
func GinHandler[B, T any](handler func(c fuego.ContextWithBody[B]) (T, error)) gin.HandlerFunc {
func GinHandler[B, T any](engine *fuego.Engine, handler func(c fuego.ContextWithBody[B]) (T, error)) gin.HandlerFunc {
return func(c *gin.Context) {
context := &ginContext[B]{
CommonContext: internal.CommonContext[B]{
Expand All @@ -65,6 +65,7 @@ func GinHandler[B, T any](handler func(c fuego.ContextWithBody[B]) (T, error)) g

resp, err := handler(context)
if err != nil {
err = engine.ErrorHandler(err)
c.Error(err)
return
}
Expand Down

0 comments on commit d6849d5

Please sign in to comment.