Skip to content

Commit

Permalink
improved hanlding of not responding node
Browse files Browse the repository at this point in the history
  • Loading branch information
MKashevsky committed Oct 18, 2018
1 parent 00d6c84 commit 901ec81
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions scorum/api/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ def get_curl_cli(url, api, method, args):

def call(url, api, method, args, retries=5):
payload = to_payload(method, api, args)

r = 0
while retries:
try:
r = requests.post(url, json=payload)
retries = 0
except Exception as e:
log.error("Error during request: %s", e)
log.warning("Remain attempts: %d", retries)
log.error("Error during request: %s\n Remain attempts: %d", e, retries)
time.sleep(0.5)
retries -= 1

if not isinstance(r, requests.Response):
raise ConnectionError("Failed to retrieve response from: %s", url)

try:
response = json.loads(r.text)
return response["result"]
except:
except KeyError:
log.error("request failed with code: %d: %s\n%s" % (r.status_code, r.reason, r.text))
return None

0 comments on commit 901ec81

Please sign in to comment.