Skip to content

Commit d7469f7

Browse files
author
SD4RK
committed
Fixed 1004 error message on get_free_games method (#22), bumped version.
1 parent 8ed09ac commit d7469f7

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

epicstore_api/api.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ class OfferData(NamedTuple):
5151
__all__ = ['EpicGamesStoreAPI', 'OfferData']
5252

5353

54+
def _clean_1004_errors(raw):
55+
# On some responses EGS API returns 1004 errors for no reason, however the responses being sent are valid otherwise.
56+
# Official launcher ignores those errors, so we probably should do that as well. That function cleans up the mess
57+
# from raw response so error handling is still possible.
58+
if 'errors' in raw:
59+
for error in raw['errors'].copy():
60+
service_response = json.loads(error.get('serviceResponse', {}))
61+
if service_response:
62+
if service_response.get('numericErrorCode') == 1004:
63+
raw['errors'].remove(error)
64+
if not raw['errors']:
65+
raw.pop('errors')
66+
return raw
67+
68+
5469
class EpicGamesStoreAPI:
5570
"""
5671
Class for interacting with EGS web API without user credentials TODO?
@@ -94,7 +109,7 @@ def get_free_games(self, allow_countries: str = None) -> dict:
94109
'freeGamesPromotions?locale={}&country={}&allowCountries={}'
95110
)
96111
api_uri = api_uri.format(self.locale, self.country, allow_countries)
97-
data = self._session.get(api_uri).json()
112+
data = _clean_1004_errors(self._session.get(api_uri).json())
98113
self._get_errors(data)
99114
return data
100115

@@ -142,22 +157,14 @@ def get_collection(self, collection: EGSCollectionType) -> dict:
142157
143158
:param collection: Needed collection type.
144159
"""
145-
raw = self._make_graphql_query(
160+
# Cleanup for the 1004 errors that always pop up by default to not mess someone up by this.
161+
raw = _clean_1004_errors(self._make_graphql_query(
146162
COLLECTION_QUERY,
147163
slug=collection.value,
148164
# This query always returns 1004 error by default. That is not controlled by us and the error itself
149165
# is happening even in the official EGS client itself, they're just ignoring it, so we will too.
150166
suppress_errors=True
151-
)
152-
# Cleanup for the 1004 errors that always pop up by default to not mess someone up by this.
153-
if 'errors' in raw:
154-
for error in raw['errors'].copy():
155-
service_response = json.loads(error.get('serviceResponse', {}))
156-
if service_response:
157-
if service_response.get('numericErrorCode') == 1004:
158-
raw['errors'].remove(error)
159-
if not raw['errors']:
160-
raw.pop('errors')
167+
))
161168
return raw
162169

163170
def fetch_media(self, media_ref_id: str) -> dict:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import setuptools
22

33
AUTHOR = 'SD4RK'
4-
VERSION = '0.1.6'
4+
VERSION = '0.1.7'
55

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

0 commit comments

Comments
 (0)