Skip to content

Commit

Permalink
api_client: show bad domain in the error
Browse files Browse the repository at this point in the history
  • Loading branch information
aviau committed Sep 6, 2024
1 parent 9454c0b commit f500bd5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions flareio/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ def _request(
) -> requests.Response:
url = urljoin("https://api.flare.io", url)

if not urlparse(url).netloc == "api.flare.io":
netloc: str = urlparse(url).netloc
if not netloc == "api.flare.io":
raise Exception(
"Please only use the client to access the api.flare.io domain."
f"You tried to use the client to access the {netloc} domain. Only api.flare.io is supported."
)

headers = {
**(headers or {}),
**self._auth_headers(),
}

return self._session.request(
method=method,
url=url,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api_client_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ def test_bad_domain() -> None:

with pytest.raises(
Exception,
match="Please only use the client to access the api.flare.io domain.",
match="You tried to use the client to access the bad.com domain. Only api.flare.io is supported.",
):
client.post("https://bad.com/hello-post")

0 comments on commit f500bd5

Please sign in to comment.