Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #73 from quintindunn/development
Browse files Browse the repository at this point in the history
Merge Development to main
  • Loading branch information
quintindunn authored Nov 24, 2023
2 parents f7ff657 + 0ca5e5c commit 35238e2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lapsepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Date: 10/22/23
"""

__version__ = '1.1.1'
__version__ = '1.1.2'

from .journal import Journal
from .auth.refresher import refresh
Expand Down
29 changes: 21 additions & 8 deletions lapsepy/journal/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,43 @@ def __init__(self, authorization: str, refresher):
}
self.refresher = refresher

def _sync_journal_call(self, query: dict) -> dict:
def _sync_journal_call(self, query: dict, reauth=True) -> dict:
"""
Makes an API call to "https://sync-service.production.journal-api.lapse.app/graphql" with an arbitrary query.
:param query: The query to send to the API.
:return: dict of the HTTP response.
"""

logger.debug(f"Making request to {self.request_url}")
try:
request = requests.post(self.request_url, headers=self.base_headers, json=query)
except AuthTokenExpired:
self.refresher()
logger.debug("Auth token expired, retrying.")
return self._sync_journal_call(query=query)
request = requests.post(self.request_url, headers=self.base_headers, json=query)

# Check for exceptions raised while making request, none of these are handled.
try:
request.raise_for_status()
except requests.exceptions.HTTPError:
raise requests.exceptions.HTTPError(request.text)

# Check for errors in response
errors = request.json().get("errors", [])

if len(errors) > 0:
# There is an error, route it and raise the appropriate error.
logger.error(f"Got error from request to {self.request_url} with query {query}.")
raise sync_journal_exception_router(error=errors[0])

try:
raise sync_journal_exception_router(error=errors[0])
except AuthTokenExpired:
# If the error is related to the AuthToken being expired, retry once.
if reauth:
self.refresher()

logger.debug("Auth token expired, retrying.")
return self._sync_journal_call(query=query, reauth=False)
else:
# Already retried it once, raise a real exception that won't be automatically caught.
raise sync_journal_exception_router(error=errors[0])

# Return the data from the API call.
return request.json()

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = "1.1.1"
VERSION = "1.1.2"
DESCRIPTION = "A Python API wrapper for the social media app Lapse."

with open("README.md", 'r') as f:
Expand Down

0 comments on commit 35238e2

Please sign in to comment.