@@ -40,11 +40,11 @@ def __init__(self) -> None:
40
40
41
41
class ServerConnectionError (Exception ):
42
42
"""
43
- Error raised if a request times out .
43
+ Error raised if we cannot connect to the server .
44
44
"""
45
45
46
46
def __init__ (self ) -> None :
47
- super ().__init__ ("The request timed out ." )
47
+ super ().__init__ ("Cannot connect to the server ." )
48
48
49
49
50
50
def json_query (proxy_vm_name : str , data : str , timeout : Optional [int ] = None ) -> str :
@@ -166,6 +166,9 @@ def _send_http_json_request(
166
166
except (TooManyRedirects , ConnectionError ):
167
167
raise ServerConnectionError
168
168
169
+ if result .status_code == http .HTTPStatus .FORBIDDEN :
170
+ raise AuthError ("forbidden" )
171
+
169
172
# Because when we download a file there is no JSON in the body
170
173
if path_query .endswith ("/download" ):
171
174
return result , result .status_code , dict (result .headers )
@@ -201,12 +204,13 @@ def _send_rpc_json_request(
201
204
raise RequestTimeoutError
202
205
elif "error" in data and result ["status" ] == http .HTTPStatus .BAD_GATEWAY :
203
206
raise ServerConnectionError
204
- elif "error" in data and result ["status" ] == 403 :
207
+ elif "error" in data and result ["status" ] == http . HTTPStatus . FORBIDDEN :
205
208
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 :
207
210
# We exclude 404 since if we encounter a 404, it means that an
208
211
# 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.
210
214
raise BaseError (data ["error" ])
211
215
212
216
return data , result ["status" ], result ["headers" ]
0 commit comments