Skip to content

Commit

Permalink
Fix #84 - update exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tjarrettveracode committed Sep 26, 2024
1 parent ad3cb4c commit b869db6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions veracode_api_py/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _rest_request(self, url, method, params=None, body=None, fullresponse=False,
raise VeracodeAPIError("Unsupported HTTP method")
except requests.exceptions.RequestException as e:
logger.exception("Error: {}".format(self.connect_error_msg))
raise VeracodeAPIError(e.text)
raise VeracodeAPIError(e.text) from e

if r.status_code != requests.codes.ok:
logger.debug("API call returned non-200 HTTP status code: {}".format(r.status_code))
Expand All @@ -119,7 +119,11 @@ def _rest_request(self, url, method, params=None, body=None, fullresponse=False,
else:
logger.exception("Error [{}]: {} for request {}".
format(r.status_code, r.text, r.request.url))
raise requests.exceptions.RequestException()
re = requests.exceptions.RequestException()
re.response = r
re.errno = r.status_code
re.request = r.request
raise re

if fullresponse:
return r
Expand Down
4 changes: 4 additions & 0 deletions veracode_api_py/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@


class VeracodeError(Exception):
def __init__(self, message):
super().__init__(message)
"""Raised when something goes wrong"""
pass


class VeracodeAPIError(Exception):
def __init__(self, message):
super().__init__(message)
"""Raised when something goes wrong with talking to the Veracode API"""
pass

0 comments on commit b869db6

Please sign in to comment.