Skip to content

Commit b9c1061

Browse files
authored
Merge pull request #830 from asimurka/exception_handling_refactor
LCORE-837: Exception handling refactor
2 parents 30df818 + ff940a9 commit b9c1061

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+8454
-3312
lines changed

docs/openapi.json

Lines changed: 3721 additions & 634 deletions
Large diffs are not rendered by default.

src/app/endpoints/authorized.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,12 @@
1212
logger = logging.getLogger(__name__)
1313
router = APIRouter(tags=["authorized"])
1414

15-
1615
authorized_responses: dict[int | str, dict[str, Any]] = {
17-
200: {
18-
"description": "The user is logged-in and authorized to access OLS",
19-
"model": AuthorizedResponse,
20-
},
21-
400: {
22-
"description": "Missing or invalid credentials provided by client for the noop and "
23-
"noop-with-token authentication modules",
24-
"model": UnauthorizedResponse,
25-
},
26-
401: {
27-
"description": "Missing or invalid credentials provided by client for the "
28-
"k8s authentication module",
29-
"model": UnauthorizedResponse,
30-
},
31-
403: {
32-
"description": "User is not authorized",
33-
"model": ForbiddenResponse,
34-
},
16+
200: AuthorizedResponse.openapi_response(),
17+
401: UnauthorizedResponse.openapi_response(
18+
examples=["missing header", "missing token"]
19+
),
20+
403: ForbiddenResponse.openapi_response(examples=["endpoint"]),
3521
}
3622

3723

src/app/endpoints/config.py

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,26 @@
99
from authentication.interface import AuthTuple
1010
from authorization.middleware import authorize
1111
from configuration import configuration
12-
from models.config import Action, Configuration
12+
from models.config import Action
13+
from models.responses import (
14+
ConfigurationResponse,
15+
ForbiddenResponse,
16+
InternalServerErrorResponse,
17+
UnauthorizedResponse,
18+
)
1319
from utils.endpoints import check_configuration_loaded
1420

1521
logger = logging.getLogger(__name__)
1622
router = APIRouter(tags=["config"])
1723

1824

1925
get_config_responses: dict[int | str, dict[str, Any]] = {
20-
200: {
21-
"name": "foo bar baz",
22-
"service": {
23-
"host": "localhost",
24-
"port": 8080,
25-
"auth_enabled": False,
26-
"workers": 1,
27-
"color_log": True,
28-
"access_log": True,
29-
"tls_config": {
30-
"tls_certificate_path": "config/certificate.crt",
31-
"tls_key_path": "config/private.key",
32-
"tls_key_password": None,
33-
},
34-
},
35-
"llama_stack": {
36-
"url": "http://localhost:8321",
37-
"api_key": "*****",
38-
"use_as_library_client": False,
39-
"library_client_config_path": None,
40-
},
41-
"user_data_collection": {
42-
"feedback_enabled": True,
43-
"feedback_storage": "/tmp/data/feedback",
44-
"transcripts_enabled": False,
45-
"transcripts_storage": None,
46-
},
47-
"mcp_servers": [
48-
{"name": "server1", "provider_id": "provider1", "url": "http://url.com:1"},
49-
{"name": "server2", "provider_id": "provider2", "url": "http://url.com:2"},
50-
{"name": "server3", "provider_id": "provider3", "url": "http://url.com:3"},
51-
],
52-
},
53-
503: {
54-
"detail": {
55-
"response": "Configuration is not loaded",
56-
}
57-
},
26+
200: ConfigurationResponse.openapi_response(),
27+
401: UnauthorizedResponse.openapi_response(
28+
examples=["missing header", "missing token"]
29+
),
30+
403: ForbiddenResponse.openapi_response(examples=["endpoint"]),
31+
500: InternalServerErrorResponse.openapi_response(examples=["configuration"]),
5832
}
5933

6034

@@ -63,15 +37,15 @@
6337
async def config_endpoint_handler(
6438
auth: Annotated[AuthTuple, Depends(get_auth_dependency())],
6539
request: Request,
66-
) -> Configuration:
40+
) -> ConfigurationResponse:
6741
"""
6842
Handle requests to the /config endpoint.
6943
7044
Process GET requests to the /config endpoint and returns the
7145
current service configuration.
7246
7347
Returns:
74-
Configuration: The loaded service configuration object.
48+
ConfigurationResponse: The loaded service configuration response.
7549
"""
7650
# Used only for authorization
7751
_ = auth
@@ -82,4 +56,4 @@ async def config_endpoint_handler(
8256
# ensure that configuration is loaded
8357
check_configuration_loaded(configuration)
8458

85-
return configuration.configuration
59+
return ConfigurationResponse(configuration=configuration.configuration)

0 commit comments

Comments
 (0)