Skip to content

Commit 023b59f

Browse files
committed
šŸ› Refactor exception handling in catalog service client to use custom error classes
1 parent f2ddafd commit 023b59f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

ā€Žservices/web/server/src/simcore_service_webserver/catalog/_catalog_rest_client_service.pyā€Ž

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
from models_library.services_types import ServiceKey, ServiceVersion
2222
from models_library.users import UserID
2323
from pydantic import TypeAdapter
24-
from servicelib.aiohttp import status
2524
from servicelib.aiohttp.client_session import get_client_session
2625
from servicelib.rest_constants import X_PRODUCT_NAME_HEADER
26+
from simcore_service_webserver.catalog.errors import (
27+
CatalogConnectionError,
28+
CatalogResponseError,
29+
)
2730
from yarl import URL
2831

2932
from .._meta import api_version_prefix
30-
from ._constants import MSG_CATALOG_SERVICE_NOT_FOUND, MSG_CATALOG_SERVICE_UNAVAILABLE
3133
from .settings import CatalogSettings, get_plugin_settings
3234

3335
_logger = logging.getLogger(__name__)
@@ -51,16 +53,17 @@ def _handle_client_exceptions(app: web.Application) -> Iterator[ClientSession]:
5153
yield session
5254

5355
except ClientResponseError as err:
54-
if err.status == status.HTTP_404_NOT_FOUND:
55-
raise web.HTTPNotFound(text=MSG_CATALOG_SERVICE_NOT_FOUND) from err
56-
raise web.HTTPServiceUnavailable(
57-
reason=MSG_CATALOG_SERVICE_UNAVAILABLE
56+
raise CatalogResponseError(
57+
status=err.status,
58+
message=err.message,
59+
headers=err.headers,
60+
request_info=err.request_info,
5861
) from err
5962

6063
except (TimeoutError, ClientConnectionError) as err:
61-
_logger.debug("Request to catalog service failed: %s", err)
62-
raise web.HTTPServiceUnavailable(
63-
reason=MSG_CATALOG_SERVICE_UNAVAILABLE
64+
raise CatalogConnectionError(
65+
message=str(err),
66+
request_info=getattr(err, "request_info", None),
6467
) from err
6568

6669

0 commit comments

Comments
Ā (0)