Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 improve error handling on pricing plans #6436

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ async def get_service_resources(request: Request):
)
@login_required
@permission_required("services.catalog.*")
@_handlers_errors.reraise_catalog_exceptions_as_http_errors
async def get_service_pricing_plan(request: Request):
ctx = CatalogRequestContext.create(request)
path_params = parse_request_path_parameters_as(ServicePathParams, request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from aiohttp import web
from servicelib.aiohttp.typing_extension import Handler

from ..resource_usage.errors import DefaultPricingPlanNotFoundError
from .exceptions import (
CatalogForbiddenError,
CatalogItemNotFoundError,
Expand All @@ -19,6 +20,7 @@ async def _wrapper(request: web.Request) -> web.StreamResponse:

except (
CatalogItemNotFoundError,
DefaultPricingPlanNotFoundError,
DefaultPricingUnitForServiceNotFoundError,
) as exc:
raise web.HTTPNotFound(reason=f"{exc}") from exc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
from ..groups.exceptions import GroupNotFoundError
from ..login.decorators import login_required
from ..projects.api import has_user_project_access_rights
from ..resource_usage.errors import DefaultPricingPlanNotFoundError
from ..security.decorators import permission_required
from ..users.api import get_user_id_from_gid, get_user_role
from ..users.exceptions import UserDefaultWalletNotFoundError
Expand Down Expand Up @@ -101,6 +102,7 @@ async def wrapper(request: web.Request) -> web.StreamResponse:
ProjectNotFoundError,
NodeNotFoundError,
UserDefaultWalletNotFoundError,
DefaultPricingPlanNotFoundError,
DefaultPricingUnitNotFoundError,
GroupNotFoundError,
CatalogItemNotFoundError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ..login.decorators import login_required
from ..notifications import project_logs
from ..products.api import Product, get_current_product
from ..resource_usage.errors import DefaultPricingPlanNotFoundError
from ..security.decorators import permission_required
from ..users import api
from ..users.exceptions import UserDefaultWalletNotFoundError
Expand All @@ -37,6 +38,7 @@
from . import projects_api
from ._common_models import ProjectPathParams, RequestContext
from .exceptions import (
DefaultPricingUnitNotFoundError,
ProjectInvalidRightsError,
ProjectNotFoundError,
ProjectStartsTooManyDynamicNodesError,
Expand All @@ -57,7 +59,12 @@ async def _wrapper(request: web.Request) -> web.StreamResponse:
try:
return await handler(request)

except (ProjectNotFoundError, UserDefaultWalletNotFoundError) as exc:
except (
ProjectNotFoundError,
UserDefaultWalletNotFoundError,
DefaultPricingPlanNotFoundError,
DefaultPricingUnitNotFoundError,
) as exc:
raise web.HTTPNotFound(reason=f"{exc}") from exc

except ProjectInvalidRightsError as exc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
from models_library.users import UserID
from models_library.wallets import WalletID
from pydantic import NonNegativeInt, parse_obj_as
from servicelib.aiohttp import status
from servicelib.aiohttp.client_session import get_client_session
from settings_library.resource_usage_tracker import ResourceUsageTrackerSettings
from yarl import URL

from ._utils import handle_client_exceptions
from .errors import DefaultPricingPlanNotFoundError
from .settings import get_plugin_settings

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -95,10 +97,15 @@ async def get_default_service_pricing_plan(
}
)
with handle_client_exceptions(app) as session:
async with session.get(url) as response:
response.raise_for_status()
body: dict = await response.json()
return parse_obj_as(PricingPlanGet, body)
try:
async with session.get(url) as response:
response.raise_for_status()
body: dict = await response.json()
return parse_obj_as(PricingPlanGet, body)
except ClientResponseError as e:
if e.status == status.HTTP_404_NOT_FOUND:
raise DefaultPricingPlanNotFoundError from e
raise


async def get_pricing_plan_unit(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ..errors import WebServerBaseError


class ResourceUsageValueError(WebServerBaseError, ValueError):
...


class DefaultPricingPlanNotFoundError(ResourceUsageValueError):
msg_template = "Default pricing plan not found"
Loading