Skip to content
This repository was archived by the owner on Jan 7, 2024. It is now read-only.

Commit d2200a8

Browse files
committed
app: make direct HTTP json request function consistent with qrexec
the behavior of the HTTP and qrexec JSON request methods must be the same in terms of which exceptions are raised when
1 parent c49ccdf commit d2200a8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

sdclientapi/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def __init__(self) -> None:
4040

4141
class ServerConnectionError(Exception):
4242
"""
43-
Error raised if a request times out.
43+
Error raised if we cannot connect to the server.
4444
"""
4545

4646
def __init__(self) -> None:
47-
super().__init__("The request timed out.")
47+
super().__init__("Cannot connect to the server.")
4848

4949

5050
def json_query(proxy_vm_name: str, data: str, timeout: Optional[int] = None) -> str:
@@ -166,6 +166,9 @@ def _send_http_json_request(
166166
except (TooManyRedirects, ConnectionError):
167167
raise ServerConnectionError
168168

169+
if result.status_code == http.HTTPStatus.FORBIDDEN:
170+
raise AuthError("forbidden")
171+
169172
# Because when we download a file there is no JSON in the body
170173
if path_query.endswith("/download"):
171174
return result, result.status_code, dict(result.headers)
@@ -201,12 +204,13 @@ def _send_rpc_json_request(
201204
raise RequestTimeoutError
202205
elif "error" in data and result["status"] == http.HTTPStatus.BAD_GATEWAY:
203206
raise ServerConnectionError
204-
elif "error" in data and result["status"] == 403:
207+
elif "error" in data and result["status"] == http.HTTPStatus.FORBIDDEN:
205208
raise AuthError(data["error"])
206-
elif "error" in data and result["status"] != 404:
209+
elif "error" in data and result["status"] != http.HTTPStatus.NOT_FOUND:
207210
# We exclude 404 since if we encounter a 404, it means that an
208211
# item is missing. In that case we return to the caller to
209-
# handle that with an appropriate message.
212+
# handle that with an appropriate message. However, if the error
213+
# is not a 404, then we raise.
210214
raise BaseError(data["error"])
211215

212216
return data, result["status"], result["headers"]

0 commit comments

Comments
 (0)