Skip to content

Commit

Permalink
Merge pull request #30 from sbabcock23/additionalerror
Browse files Browse the repository at this point in the history
Error Handling
  • Loading branch information
sbabcock23 authored Dec 14, 2023
2 parents 6bf9f61 + ec36169 commit 4763f7c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ tryfi.pets[0].monthlyNap

# Version History

# 0.0.21
- Enchanced error handling of pet information in case its not available

# 0.0.20
- Fix - Added HTTP Header to the requests of all GraphQL requests

Expand Down
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.20"
PYTRYFI_VERSION = "0.0.21"

API_HOST_URL_BASE = "https://api.tryfi.com"
API_GRAPHQL = "/graphql"
Expand Down
39 changes: 32 additions & 7 deletions pytryfi/fiPet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,47 @@ def __init__(self, petId):
def setPetDetailsJSON(self, petJSON):
try:
self._name = petJSON['name']
except:
LOGGER.warning(f"Unknown Pet Name")
self._name = "Unknown Pet Name"
try:
self._homeCityState = petJSON['homeCityState']
except:
LOGGER.warning(f"Unknown City")
self._homeCityState = "FakeCity"
try:
self._yearOfBirth = int(petJSON['yearOfBirth'])
except:
LOGGER.warning(f"Unknown Year of Birth")
self._yearOfBirth = 1900
try:
self._monthOfBirth = int(petJSON['monthOfBirth'])
except:
LOGGER.warning(f"Unknown Month of Birth")
self._monthOfBirth = 1
try:
self._dayOfBirth = int(petJSON['dayOfBirth'])
except:
LOGGER.warning(f"Unknown day of birth")
self._dayOfBirth = 1
try:
self._gender = petJSON['gender']
except:
LOGGER.warning(f"Unknown Gender")
self._gender = "Male"
try:
#weight is in kg
self._weight = float(petJSON['weight'])
except:
LOGGER.warning(f"Unknown Weight")
self._weight = float(1.00)
try:
self._breed = petJSON['breed']['name']
except:
LOGGER.warning(f"Unknown Breed of Dog")
self._breed = "Dog"
#track last updated
self._lastUpdated = datetime.datetime.now()
except TryFiError as e:
LOGGER.error(f"Unable to set values for Pet.\nException: {e}\nwhile parsing {petJSON}")
capture_exception(e)
raise TryFiError("Unable to set Pet Details")
except Exception as e:
capture_exception(e)
self._lastUpdated = datetime.datetime.now()
try:
self._photoLink = petJSON['photos']['first']['image']['fullSize']
except Exception as e:
Expand Down

0 comments on commit 4763f7c

Please sign in to comment.