Added exception handling for unhandled api requests
This commit is contained in:
parent
86976e5133
commit
2b9ebdeab2
@ -170,21 +170,25 @@ def cf_api(endpoint, method, config, headers={}, data=False):
|
||||
"X-Auth-Email": config['authentication']['api_key']['account_email'],
|
||||
"X-Auth-Key": config['authentication']['api_key']['api_key'],
|
||||
}
|
||||
try:
|
||||
if(data == False):
|
||||
response = requests.request(
|
||||
method, "https://api.cloudflare.com/client/v4/" + endpoint, headers=headers)
|
||||
else:
|
||||
response = requests.request(
|
||||
method, "https://api.cloudflare.com/client/v4/" + endpoint,
|
||||
headers=headers, json=data)
|
||||
|
||||
if(data == False):
|
||||
response = requests.request(
|
||||
method, "https://api.cloudflare.com/client/v4/" + endpoint, headers=headers)
|
||||
else:
|
||||
response = requests.request(
|
||||
method, "https://api.cloudflare.com/client/v4/" + endpoint,
|
||||
headers=headers, json=data)
|
||||
|
||||
if response.ok:
|
||||
return response.json()
|
||||
else:
|
||||
print("📈 Error sending '" + method +
|
||||
"' request to '" + response.url + "':")
|
||||
print(response.text)
|
||||
if response.ok:
|
||||
return response.json()
|
||||
else:
|
||||
print("😡 Error sending '" + method +
|
||||
"' request to '" + response.url + "':")
|
||||
print(response.text)
|
||||
return None
|
||||
except Exception as e:
|
||||
print("😡 An exception occurred while sending '" +
|
||||
method + "' request to '" + endpoint + "': " + str(e))
|
||||
return None
|
||||
|
||||
|
||||
@ -209,8 +213,8 @@ if __name__ == '__main__':
|
||||
config = json.loads(config_file.read())
|
||||
except:
|
||||
print("😡 Error reading config.json")
|
||||
# wait 60 seconds to prevent excessive logging on docker auto restart
|
||||
time.sleep(60)
|
||||
# wait 10 seconds to prevent excessive logging on docker auto restart
|
||||
time.sleep(10)
|
||||
|
||||
if config is not None:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user