SlimG commited on
Commit
9316f10
·
1 Parent(s): 259a596

improve resilience to non-existing remote endpoints

Browse files
Files changed (2) hide show
  1. src/api_factory.py +1 -0
  2. src/main.py +6 -0
src/api_factory.py CHANGED
@@ -41,6 +41,7 @@ async def get_remote_params(base_url: str,
41
  params = method_def.get("parameters", [])
42
 
43
  return {
 
44
  "general": {
45
  "description": method_def.get("description", ""),
46
  "summary": method_def.get("summary", ""),
 
41
  params = method_def.get("parameters", [])
42
 
43
  return {
44
+ "found": bool(path_def),
45
  "general": {
46
  "description": method_def.get("description", ""),
47
  "summary": method_def.get("summary", ""),
src/main.py CHANGED
@@ -85,6 +85,12 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
85
  endpoint_def = await get_remote_params(base_url=TENNIS_ML_API,
86
  endpoint=endpoint,
87
  method='get')
 
 
 
 
 
 
88
  forward_endpoint = create_forward_endpoint(base_url=TENNIS_ML_API,
89
  _endpoint=endpoint,
90
  param_defs=endpoint_def["params"])
 
85
  endpoint_def = await get_remote_params(base_url=TENNIS_ML_API,
86
  endpoint=endpoint,
87
  method='get')
88
+
89
+ if not endpoint_def["found"]:
90
+ logger.warning(f"Endpoint {endpoint} not found in the remote API")
91
+ continue
92
+
93
+ # Create a forward endpoint for the remote API
94
  forward_endpoint = create_forward_endpoint(base_url=TENNIS_ML_API,
95
  _endpoint=endpoint,
96
  param_defs=endpoint_def["params"])