Skip to content

Commit

Permalink
Fixed 1004 error message on get_free_games method (#22), bumped version.
Browse files Browse the repository at this point in the history
  • Loading branch information
SD4RK committed Oct 8, 2023
1 parent 8ed09ac commit d7469f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 19 additions & 12 deletions epicstore_api/api.py
Expand Up @@ -51,6 +51,21 @@ class OfferData(NamedTuple):
__all__ = ['EpicGamesStoreAPI', 'OfferData']


def _clean_1004_errors(raw):
# On some responses EGS API returns 1004 errors for no reason, however the responses being sent are valid otherwise.
# Official launcher ignores those errors, so we probably should do that as well. That function cleans up the mess
# from raw response so error handling is still possible.
if 'errors' in raw:
for error in raw['errors'].copy():
service_response = json.loads(error.get('serviceResponse', {}))
if service_response:
if service_response.get('numericErrorCode') == 1004:
raw['errors'].remove(error)
if not raw['errors']:
raw.pop('errors')
return raw


class EpicGamesStoreAPI:
"""
Class for interacting with EGS web API without user credentials TODO?
Expand Down Expand Up @@ -94,7 +109,7 @@ def get_free_games(self, allow_countries: str = None) -> dict:
'freeGamesPromotions?locale={}&country={}&allowCountries={}'
)
api_uri = api_uri.format(self.locale, self.country, allow_countries)
data = self._session.get(api_uri).json()
data = _clean_1004_errors(self._session.get(api_uri).json())
self._get_errors(data)
return data

Expand Down Expand Up @@ -142,22 +157,14 @@ def get_collection(self, collection: EGSCollectionType) -> dict:
:param collection: Needed collection type.
"""
raw = self._make_graphql_query(
# Cleanup for the 1004 errors that always pop up by default to not mess someone up by this.
raw = _clean_1004_errors(self._make_graphql_query(
COLLECTION_QUERY,
slug=collection.value,
# This query always returns 1004 error by default. That is not controlled by us and the error itself
# is happening even in the official EGS client itself, they're just ignoring it, so we will too.
suppress_errors=True
)
# Cleanup for the 1004 errors that always pop up by default to not mess someone up by this.
if 'errors' in raw:
for error in raw['errors'].copy():
service_response = json.loads(error.get('serviceResponse', {}))
if service_response:
if service_response.get('numericErrorCode') == 1004:
raw['errors'].remove(error)
if not raw['errors']:
raw.pop('errors')
))
return raw

def fetch_media(self, media_ref_id: str) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
@@ -1,7 +1,7 @@
import setuptools

AUTHOR = 'SD4RK'
VERSION = '0.1.6'
VERSION = '0.1.7'

with open("README.md", "r") as fh:
long_description = fh.read()
Expand Down

0 comments on commit d7469f7

Please sign in to comment.