diff --git a/src/satosa/routing.py b/src/satosa/routing.py index 317b047f9..9d2769e44 100644 --- a/src/satosa/routing.py +++ b/src/satosa/routing.py @@ -151,10 +151,7 @@ def endpoint_routing(self, context): ) logger.debug(logline) raise SATOSABadContextError("Context did not contain any path") - - msg = "Routing path: {path}".format(path=context.path) - logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg) - logger.debug(logline) + path_split = context.path.split("/") backend = path_split[0] @@ -167,6 +164,10 @@ def endpoint_routing(self, context): ) logger.debug(logline) + msg = "Routing path: {path}".format(path=context.path) + logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg) + logger.debug(logline) + try: name, frontend_endpoint = self._find_registered_endpoint(context, self.frontends) except ModuleRouter.UnknownEndpoint: @@ -183,9 +184,12 @@ def endpoint_routing(self, context): context.target_micro_service = name return micro_service_endpoint - if backend in self.backends: - backend_endpoint = self._find_registered_backend_endpoint(context) - if backend_endpoint: - return backend_endpoint - + try: + name, backend_endpoint = self._find_registered_endpoint(context, self.backends) + except ModuleRouter.UnknownEndpoint: + pass + else: + context.target_backend = name + return backend_endpoint + raise SATOSANoBoundEndpointError("'{}' not bound to any function".format(context.path))