@@ -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+
5469class 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 :
0 commit comments