Skip to content

Commit

Permalink
Merge pull request #6038 from MerlionRock/dev
Browse files Browse the repository at this point in the history
Exceptions Added
  • Loading branch information
Jcolomar authored May 11, 2017
2 parents ff314cd + 4169ee5 commit f1096f7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from .inventory import init_inventory, player
from sys import platform as _platform
from pgoapi.protos.pogoprotos.enums import badge_type_pb2
from pgoapi.exceptions import AuthException, NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException, NoPlayerPositionSetException
from pgoapi.exceptions import AuthException, NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException, NoPlayerPositionSetException, HashingOfflineException
from pgoapi.hash_server import HashServer


Expand Down Expand Up @@ -1541,7 +1541,12 @@ def heartbeat(self):
request = self.api.create_request()
request.get_player()
request.check_awarded_badges()
responses = request.call()
try:
responses = request.call()
except NotLoggedInException:
self.logger.warning('Unable to login, retying')
except:
self.logger.warning('Error occured in heatbeat, retying')

if responses['responses']['GET_PLAYER']['success'] == True:
# we get the player_data anyway, might as well store it
Expand Down
13 changes: 12 additions & 1 deletion pokemongo_bot/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
from pgoapi.exceptions import (ServerSideRequestThrottlingException,
NotLoggedInException, ServerBusyOrOfflineException,
NoPlayerPositionSetException,
NoPlayerPositionSetException, HashingOfflineException,
UnexpectedResponseException)
from pgoapi.pgoapi import PGoApi
from pgoapi.pgoapi import PGoApiRequest
Expand Down Expand Up @@ -209,12 +209,23 @@ def call(self, max_retry=15):
self._req_method_list = [req_method for req_method in api_req_method_list]
should_throttle_retry = False
should_unexpected_response_retry = False
hashing_offline = False

try:
result = self._call()
except ServerSideRequestThrottlingException:
should_throttle_retry = True
except HashingOfflineException:
hashing_offline = True
except UnexpectedResponseException:
should_unexpected_response_retry = True
except:
should_unexpected_response_retry = True

if hashing_offline:
self.logger.warning('Hashing server issue, retrying in 5 Secs...')
sleep(5)
continue

if should_throttle_retry:
throttling_retry += 1
Expand Down
5 changes: 4 additions & 1 deletion pokemongo_bot/event_handlers/social_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ def initialize(self):
return

def run(self):
self._mqttc.connect("broker.pikabot.org", 1883, 20)
try:
self._mqttc.connect("broker.pikabot.org", 1883, 20)
except:
print('Error occured in social handler')
while True:
try:
self._mqttc.loop_forever(timeout=30.0, max_packets=100, retry_first_connection=False)
Expand Down

0 comments on commit f1096f7

Please sign in to comment.