-
-
Notifications
You must be signed in to change notification settings - Fork 31
Differenctiate ValueError
s
#143
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,10 @@ def _contain_placeholder(url: str, placeholder: str = "package_name") -> bool: | |
return placeholder in fields | ||
|
||
|
||
class UnsupportedContentTypeError(Exception): | ||
pass | ||
|
||
|
||
def _select_parser(content_type: str, pkgname: str) -> Callable[[str], ProjectInfo]: | ||
""" | ||
Select the function to parse the response based on the content type. | ||
|
@@ -234,7 +238,13 @@ def _select_parser(content_type: str, pkgname: str) -> Callable[[str], ProjectIn | |
): | ||
return partial(ProjectInfo.from_simple_html_api, pkgname=pkgname) | ||
case _: | ||
raise ValueError(f"Unsupported content type: {content_type}") | ||
raise UnsupportedContentTypeError( | ||
f"Unsupported content type: {content_type}" | ||
) | ||
|
||
|
||
class NoValidIndexForPackageError(Exception): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be a synonym of PackageNotFoundError from importlib.metadata which is used un the same file... I've used a slightly longer name to differentiate. |
||
pass | ||
|
||
|
||
async def query_package( | ||
|
@@ -296,14 +306,11 @@ async def query_package( | |
raise | ||
|
||
content_type = headers.get("content-type", "").lower() | ||
try: | ||
parser = _select_parser(content_type, name) | ||
except ValueError as e: | ||
raise ValueError(f"Error trying to decode url: {url}") from e | ||
parser = _select_parser(content_type, name) | ||
return parser(metadata) | ||
else: | ||
raise ValueError( | ||
f"Can't fetch metadata for '{name}'. " | ||
raise NoValidIndexForPackageError( | ||
f"Can't fetch metadata for {name!r}. " | ||
"Please make sure you have entered a correct package name " | ||
"and correctly specified index_urls (if you changed them)." | ||
) |
Uh oh!
There was an error while loading. Please reload this page.