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

fix: exceptions handling update #829

Merged
merged 1 commit into from Sep 14, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions eodag/plugins/crunch/filter_latest_tpl_name.py
Expand Up @@ -20,7 +20,7 @@
import re

from eodag.plugins.crunch.base import Crunch
from eodag.utils.exceptions import MisconfiguredError
from eodag.utils.exceptions import ValidationError

logger = logging.getLogger("eodag.plugins.crunch.filter_latest_tpl_name")

Expand All @@ -43,7 +43,7 @@ def __init__(self, config):
super(FilterLatestByName, self).__init__(config)
name_pattern = config.pop("name_pattern")
if not self.NAME_PATTERN_CONSTRAINT.search(name_pattern):
raise MisconfiguredError(
raise ValidationError(
"Name pattern should respect the regex: {}".format(
self.NAME_PATTERN_CONSTRAINT.pattern
)
Expand Down
2 changes: 1 addition & 1 deletion eodag/rest/server.py
Expand Up @@ -209,7 +209,6 @@ async def default_exception_handler(request: Request, error):
)


@app.exception_handler(MisconfiguredError)
@app.exception_handler(NoMatchingProductType)
@app.exception_handler(UnsupportedProductType)
@app.exception_handler(UnsupportedProvider)
Expand Down Expand Up @@ -238,6 +237,7 @@ async def handle_resource_not_found(request: Request, error):
)


@app.exception_handler(MisconfiguredError)
@app.exception_handler(AuthenticationError)
async def handle_auth_error(request: Request, error):
"""AuthenticationError should be sent as internal server error to the client"""
Expand Down
3 changes: 1 addition & 2 deletions eodag/rest/stac.py
Expand Up @@ -45,7 +45,6 @@
urljoin,
)
from eodag.utils.exceptions import (
MisconfiguredError,
NoMatchingProductType,
NotAvailableError,
ValidationError,
Expand Down Expand Up @@ -361,7 +360,7 @@ def __filter_item_model_properties(self, item_model, product_type):
if pt["ID"] == product_type
][0]
except IndexError:
raise MisconfiguredError(
raise NoMatchingProductType(
"Product type {} not available for {}".format(
product_type, self.provider
)
Expand Down
2 changes: 1 addition & 1 deletion eodag/rest/utils.py
Expand Up @@ -721,7 +721,7 @@ def search_stac_items(url, arguments, root="/", catalogs=[], provider=None):
)
arguments.pop("collections")
else:
raise NoMatchingProductType("No product_type found in collections argument")
raise NoMatchingProductType("Invalid request, collections argument is missing")

# get products by ids
ids = arguments.get("ids", None)
Expand Down
8 changes: 5 additions & 3 deletions eodag/utils/__init__.py
Expand Up @@ -72,6 +72,7 @@
from tqdm.auto import tqdm

from eodag.utils import logging as eodag_logging
from eodag.utils.exceptions import MisconfiguredError

try:
from importlib.metadata import metadata # type: ignore
Expand Down Expand Up @@ -995,9 +996,10 @@ def format_string(key, str_to_format, **format_variables):
# defaultdict usage will return "" for missing keys in format_args
try:
result = str_to_format.format_map(defaultdict(str, **format_variables))
except TypeError:
logger.error("Unable to format str=%s" % str_to_format)
raise
except TypeError as e:
raise MisconfiguredError(
f"Unable to format str={str_to_format} using {str(format_variables)}: {str(e)}"
)

# try to convert string to python object
try:
Expand Down