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