From 795585e01e85fa4cbb90bbbc2b5d1d690998c8af Mon Sep 17 00:00:00 2001 From: David Hontecillas Date: Wed, 5 Mar 2025 14:58:48 +0100 Subject: [PATCH] return 500 error when calling and endpoint that failed to build the proxy pipeline Signed-off-by: David Hontecillas --- router/gin/router.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/router/gin/router.go b/router/gin/router.go index 21b2fa127..2d4089b21 100644 --- a/router/gin/router.go +++ b/router/gin/router.go @@ -133,11 +133,16 @@ func (r ginRouter) registerEndpointsAndMiddlewares(cfg config.ServiceConfig) { } func (r ginRouter) registerKrakendEndpoints(rg *gin.RouterGroup, cfg config.ServiceConfig) { + proxyBuildFailedHandler := func(c *gin.Context) { + c.AbortWithStatus(http.StatusInternalServerError) + } // build and register the pipes and endpoints sequentially for _, c := range cfg.Endpoints { proxyStack, err := r.cfg.ProxyFactory.New(c) if err != nil { r.cfg.Logger.Error(logPrefix, "Calling the ProxyFactory", err.Error()) + r.registerKrakendEndpoint(rg, c.Method, c, + proxyBuildFailedHandler, 1) continue } r.registerKrakendEndpoint(rg, c.Method, c, r.cfg.HandlerFactory(c, proxyStack), len(c.Backend))