Skip to content

Commit

Permalink
Use "raise from"
Browse files Browse the repository at this point in the history
  • Loading branch information
m-aciek committed Aug 7, 2023
1 parent 4d1c0a7 commit d436e6a
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions wlc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,30 +129,34 @@ def process_error(self, error):
headers = error.response.headers
raise WeblateThrottlingError(
headers.get("X-RateLimit-Limit"), headers.get("Retry-After")
)
) from error
if status_code == 404:
raise WeblateException(
"Object not found on the server "
"(maybe operation is not supported on the server)"
)
) from error
if status_code == 403:
raise WeblatePermissionError(self.permission_error_message(error))
raise WeblatePermissionError(
self.permission_error_message(error)
) from error

if status_code == 401:
raise WeblateDeniedError
raise WeblateDeniedError from error

if 300 <= status_code < 400:
raise WeblateException(
"Server responded with an unexpectedHTTP redirect. "
"Please check your configuration."
)
) from error

reason = error.response.reason
try:
error_string = str(error.response.json())
except Exception:
error_string = ""
raise WeblateException(f"HTTP error {status_code}: {reason} {error_string}")
raise WeblateException(
f"HTTP error {status_code}: {reason} {error_string}"
) from error

def raw_request(self, method, path, data=None, files=None, params=None):
"""Construct request object and returns raw content."""
Expand All @@ -166,8 +170,8 @@ def request(self, method, path, data=None, files=None, params=None):

try:
return response.json()
except ValueError:
raise WeblateException("Server returned invalid JSON")
except ValueError as error:
raise WeblateException("Server returned invalid JSON") from error

def invoke_request(self, method, path, data=None, files=None, params=None):
"""Construct request object."""
Expand Down Expand Up @@ -421,8 +425,8 @@ def __getattr__(self, name):
self.refresh()
try:
return self._data[name]
except KeyError:
raise AttributeError(name)
except KeyError as error:
raise AttributeError(name) from error

def setattrvalue(self, name, value):
if name not in self.PARAMS:
Expand Down

0 comments on commit d436e6a

Please sign in to comment.