Skip to content

Commit f3eef8b

Browse files
authored
refactor(client): move guard clause to top of _request method (#78)
Fixes #74
1 parent 5f734f7 commit f3eef8b

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/re3data/_client.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"User-Agent": f"python-re3data/{__version__}",
2222
}
2323
DEFAULT_TIMEOUT = httpx.Timeout(timeout=10.0) # timeout in seconds
24+
ALLOWED_RETURN_TYPES = {"xml", "response"}
2425

2526

2627
def log_response(response: httpx.Response) -> None:
@@ -136,15 +137,13 @@ def _request(self, endpoint: str, return_type: str) -> str | httpx.Response:
136137
httpx.RequestError: If the request fails or times out.
137138
ValueError: If an invalid `return_type` is provided.
138139
"""
140+
if return_type not in ALLOWED_RETURN_TYPES:
141+
raise ValueError(f"Invalid `return_type`: {return_type}. Expected one of: {ALLOWED_RETURN_TYPES}")
139142
response = self._client.get(endpoint)
140143
response.raise_for_status()
141-
match return_type:
142-
case "xml":
143-
return response.text
144-
case "response":
145-
return response
146-
case _:
147-
raise ValueError(f"Invalid `return_type`: {return_type}. Expected one of: `xml`, `response`.")
144+
if return_type == "xml":
145+
return response.text
146+
return response
148147

149148
@property
150149
def repositories(self) -> RepositoryManager:

0 commit comments

Comments
 (0)