Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errorreporting #9

Merged
merged 6 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ tryfi.pets[0].isLost
* [TryFi](https://tryfi.com/)

# Version History
# 0.0.13
* Enhancement - removed error logging where not required
* Fix - resolved issue where the variables are unbound in the login function

## 0.0.12
* Enhancement - added Sentry for capturing errors by further only capturing exceptions

Expand Down
38 changes: 20 additions & 18 deletions pytryfi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def __init__(self, username=None, password=None):
sentry = sentry_sdk.init(
SENTRY_URL,
release=PYTRYFI_VERSION,
traces_sample_rate=0,
)
self._api_host = API_HOST_URL_BASE
self._session = requests.Session()
Expand Down Expand Up @@ -168,6 +167,7 @@ def session(self):

# login to the api and get a session
def login(self):
error = None
url = API_HOST_URL_BASE + API_LOGIN
params={
'email' : self._username,
Expand All @@ -178,26 +178,28 @@ def login(self):
try:
response = self._session.post(url, data=params)
response.raise_for_status()
#validate if the response contains error or not
try:
error = response.json()['error']
except Exception as e:
#capture_exception(e)
error = None
#if error set or response is non-200
if error or not response.ok:
errorMsg = error['message']
LOGGER.error(f"Cannot login, response: ({response.status_code}): {errorMsg} ")
capture_exception(errorMsg)
raise Exception("TryFiLoginError")

#storing cookies but don't need them. Handled by session mgmt
self._cookies = response.cookies
#store unique userId from login for future use
self._userId = response.json()['userId']
self._sessionId = response.json()['sessionId']
LOGGER.debug(f"Successfully logged in. UserId: {self._userId}")
except requests.RequestException as e:
LOGGER.error(f"Cannot login, error: ({e})")
capture_exception(e)
raise requests.RequestException(e)
except Exception as e:
capture_exception(e)
error = None
try:
error = response.json()['error']
except Exception as e:
capture_exception(e)
error = None
if error or not response.ok:
errorMsg = error['message']
LOGGER.error(f"Cannot login, response: ({response.status_code}): {errorMsg} ")
capture_exception(errorMsg)
raise Exception("TryFiLoginError")
#storing cookies but don't need them. Handled by session mgmt
self._cookies = response.cookies
#store unique userId from login for future use
self._userId = response.json()['userId']
self._sessionId = response.json()['sessionId']
LOGGER.debug(f"Successfully logged in. UserId: {self._userId}")
2 changes: 1 addition & 1 deletion pytryfi/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SENTRY_URL = "https://[email protected]/5735605"

PYTRYFI_VERSION = "0.0.12"
PYTRYFI_VERSION = "0.0.13"

API_HOST_URL_BASE = "https://api.tryfi.com"
API_GRAPHQL = "/graphql"
Expand Down
4 changes: 2 additions & 2 deletions pytryfi/fiPet.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setPetDetailsJSON(self, petJSON):
try:
self._photoLink = petJSON['photos']['first']['image']['fullSize']
except Exception as e:
capture_exception(e)
#capture_exception(e)
LOGGER.warning(f"Cannot find photo of your pet. Defaulting to empty string.")
self._photoLink = ""
try:
Expand Down Expand Up @@ -66,7 +66,7 @@ def setCurrentLocation(self, activityJSON):
self._currPlaceName = activityJSON['place']['name']
self._currPlaceAddress = activityJSON['place']['address']
except Exception as e:
capture_exception(e)
#capture_exception(e)
LOGGER.warning("Could not set place, defaulting to Unknown")
self._currPlaceName = "UNKNOWN"
self._currPlaceAddress = "UNKNOWN"
Expand Down