1- from aiohttp import web
21from servicelib .aiohttp import status
3- from servicelib .aiohttp .rest_responses import create_http_error
4- from servicelib .aiohttp .web_exceptions_extension import get_http_error_class_or_none
52from simcore_service_webserver .director_v2 .exceptions import DirectorServiceError
63
74from ...exception_handling import (
1714_exceptions_handlers_map : ExceptionHandlersMap = {}
1815
1916
20- async def _handler_director_service_error (
21- request : web .Request , exception : Exception
22- ) -> web .Response :
23- assert request # nosec
24-
25- assert isinstance (exception , DirectorServiceError ) # nosec
26- return create_http_error (
27- exception ,
28- reason = exception .reason ,
29- http_error_cls = get_http_error_class_or_none (exception .status )
30- or web .HTTPServiceUnavailable ,
31- )
32-
33-
34- _exceptions_handlers_map [DirectorServiceError ] = _handler_director_service_error
35-
36-
3717_TO_HTTP_ERROR_MAP : ExceptionToHttpErrorMap = {
3818 UserDefaultWalletNotFoundError : HttpErrorInfo (
3919 status .HTTP_404_NOT_FOUND ,
@@ -43,6 +23,10 @@ async def _handler_director_service_error(
4323 status .HTTP_402_PAYMENT_REQUIRED ,
4424 "Wallet does not have enough credits for computations. {reason}" ,
4525 ),
26+ DirectorServiceError : HttpErrorInfo (
27+ status .HTTP_503_SERVICE_UNAVAILABLE ,
28+ "This service is currently not available. The incident was logged and will be investigated. Please try again later." ,
29+ ),
4630}
4731
4832_exceptions_handlers_map .update (to_exceptions_handlers_map (_TO_HTTP_ERROR_MAP ))
0 commit comments