Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
matusdrobuliak66 committed Nov 8, 2023
1 parent 9f68dfd commit e9d13d1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@


class ResourceUsageTrackerRuntimeError(PydanticErrorMixin, RuntimeError):
msg: str = "Resource-usage-tracker unexpected error"
msg_template: str = "Resource-usage-tracker unexpected error"


class ConfigurationError(ResourceUsageTrackerRuntimeError):
msg: str = "Application misconfiguration"
msg_template: str = "Application misconfiguration: {msg}"


class CustomResourceUsageTrackerError(ResourceUsageTrackerRuntimeError):
msg: str
msg_template: str = "Error: {msg}"


def http404_error_handler(
request: Request, # pylint: disable=unused-argument
error: CustomResourceUsageTrackerError,
) -> JSONResponse:
return JSONResponse(status_code=404, content={"message": error.msg})
return JSONResponse(status_code=404, content={"message": f"{error.msg_template}"})
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
MSG_CATALOG_SERVICE_UNAVAILABLE: Final[
str
] = "Currently catalog service is unavailable, please try again later"

MSG_CATALOG_SERVICE_NOT_FOUND: Final[str] = "Not Found"
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from yarl import URL

from .._meta import api_version_prefix
from ._constants import MSG_CATALOG_SERVICE_UNAVAILABLE
from ._constants import MSG_CATALOG_SERVICE_NOT_FOUND, MSG_CATALOG_SERVICE_UNAVAILABLE
from .settings import get_plugin_settings

_logger = logging.getLogger(__name__)
Expand All @@ -41,7 +41,7 @@ def _handle_client_exceptions(app: web.Application) -> Iterator[ClientSession]:

except ClientResponseError as err:
if err.status == 404:
raise web.HTTPNotFound(reason=f"{err.message}")
raise web.HTTPNotFound(reason=MSG_CATALOG_SERVICE_NOT_FOUND)
raise web.HTTPServiceUnavailable(
reason=MSG_CATALOG_SERVICE_UNAVAILABLE
) from err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
MSG_RESOURCE_USAGE_TRACKER_SERVICE_UNAVAILABLE: Final[
str
] = "Currently resource usage tracker service is unavailable, please try again later"

MSG_RESOURCE_USAGE_TRACKER_NOT_FOUND: Final[str] = "Not Found"
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from aiohttp.client_exceptions import ClientConnectionError, ClientResponseError
from servicelib.aiohttp.client_session import get_client_session

from ._constants import MSG_RESOURCE_USAGE_TRACKER_SERVICE_UNAVAILABLE
from ._constants import (
MSG_RESOURCE_USAGE_TRACKER_NOT_FOUND,
MSG_RESOURCE_USAGE_TRACKER_SERVICE_UNAVAILABLE,
)

_logger = logging.getLogger(__name__)

Expand All @@ -20,7 +23,7 @@ def handle_client_exceptions(app: web.Application) -> Iterator[ClientSession]:
yield session
except (ClientResponseError) as err:
if err.status == 404:
raise web.HTTPNotFound(reason=f"{err.message}")
raise web.HTTPNotFound(reason=MSG_RESOURCE_USAGE_TRACKER_NOT_FOUND)
raise web.HTTPServiceUnavailable(
reason=MSG_RESOURCE_USAGE_TRACKER_SERVICE_UNAVAILABLE
) from err
Expand Down

0 comments on commit e9d13d1

Please sign in to comment.