Skip to content

Commit d0aa4cd

Browse files
committed
refactor(rlsapi): tighten infer exception typing
Signed-off-by: Major Hayden <major@redhat.com>
1 parent d35ecfb commit d0aa4cd

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/app/endpoints/rlsapi_v1.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646

4747
# Default values when RH Identity auth is not configured
4848
AUTH_DISABLED = "auth_disabled"
49+
# Keep this tuple centralized so infer_endpoint can catch all expected backend
50+
# failures in one place while preserving a single telemetry/error-mapping path.
51+
_INFER_HANDLED_EXCEPTIONS = (
52+
RuntimeError,
53+
APIConnectionError,
54+
RateLimitError,
55+
APIStatusError,
56+
OpenAIAPIStatusError,
57+
)
4958

5059

5160
def _get_rh_identity_context(request: Request) -> tuple[str, str]:
@@ -361,7 +370,7 @@ async def infer_endpoint(
361370
input_source = infer_request.get_input_source()
362371
instructions = _build_instructions(infer_request.context.systeminfo)
363372
model_id = _get_default_model_id()
364-
mcp_tools = await get_mcp_tools(request_headers=request.headers)
373+
mcp_tools: list[Any] = await get_mcp_tools(request_headers=request.headers)
365374
logger.debug(
366375
"Request %s: Combined input source length: %d", request_id, len(input_source)
367376
)
@@ -375,13 +384,7 @@ async def infer_endpoint(
375384
model_id=model_id,
376385
)
377386
inference_time = time.monotonic() - start_time
378-
except (
379-
RuntimeError,
380-
APIConnectionError,
381-
RateLimitError,
382-
APIStatusError,
383-
OpenAIAPIStatusError,
384-
) as error:
387+
except _INFER_HANDLED_EXCEPTIONS as error:
385388
_record_inference_failure(
386389
background_tasks,
387390
infer_request,

0 commit comments

Comments
 (0)