Skip to content

Commit

Permalink
Introduce use of app-specific exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchrisadams committed Nov 13, 2024
1 parent dd83624 commit 695a776
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/carbon_txt/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import logging
import rich # noqa

from .exceptions import UnreachableCarbonTxtFile

logger = logging.getLogger(__name__)

logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -129,8 +131,13 @@ def resolve_uri(self, uri: str) -> str:
return str(path_to_file.resolve())

# if the URI is a valid HTTP or HTTPS URI, we check if the URI is reachable
response = httpx.head(parsed_uri.geturl())

# and if there is a 'via' header in the response, we follow that
try:
response = httpx.head(parsed_uri.geturl())
except httpx._exceptions.ConnectError:
raise UnreachableCarbonTxtFile(
f"Could not connect to {parsed_uri.geturl()}."
)
# catch any errors from the request
response.raise_for_status()

Expand Down

0 comments on commit 695a776

Please sign in to comment.