Skip to content

Commit 3483f25

Browse files
committed
add too many requests error
1 parent 8a0e697 commit 3483f25

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

weconnect/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ class RetrievalError(Exception):
22
pass
33

44

5+
class TooManyRequestsError(RetrievalError):
6+
pass
7+
8+
59
class SetterError(Exception):
610
pass
711

weconnect/weconnect.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from weconnect.elements.charging_station import ChargingStation
1818
from weconnect.elements.general_controls import GeneralControls
1919
from weconnect.addressable import AddressableLeaf, AddressableObject, AddressableDict
20-
from weconnect.errors import RetrievalError
20+
from weconnect.errors import RetrievalError, TooManyRequestsError
2121
from weconnect.weconnect_errors import ErrorEventType
2222
from weconnect.util import ExtendedEncoder
2323

@@ -370,6 +370,11 @@ def fetchData(self, url, force=False, allowEmpty=False, allowHttpError=False, al
370370
data = statusResponse.json()
371371
if self.cache is not None:
372372
self.cache[url] = (data, str(datetime.utcnow()))
373+
elif statusResponse.status_code in (requests.codes['too_many_requests']):
374+
self.notifyError(self, ErrorEventType.HTTP, str(statusResponse.status_code),
375+
'Could not fetch data due to too many requests from your account')
376+
raise TooManyRequestsError('Could not fetch data due to too many requests from your account. '
377+
f'Status Code was: {statusResponse.status_code}')
373378
elif statusResponse.status_code == requests.codes['unauthorized']:
374379
LOG.info('Server asks for new authorization')
375380
self.login()

0 commit comments

Comments
 (0)