Updated error handling to provide specific message for rate limit exceeded condition (#657)
This commit is contained in:
parent
b4c5276feb
commit
0354ff6cc4
|
@ -174,32 +174,48 @@ def check_for_update():
|
||||||
# Fetch the latest release information from GitHub API
|
# Fetch the latest release information from GitHub API
|
||||||
latest_release_url = f"https://api.github.com/repos/AdnanHodzic/auto-cpufreq/releases/latest"
|
latest_release_url = f"https://api.github.com/repos/AdnanHodzic/auto-cpufreq/releases/latest"
|
||||||
try:
|
try:
|
||||||
latest_release = requests.get(latest_release_url).json()
|
response = requests.get(latest_release_url)
|
||||||
|
if response.status_code == 200:
|
||||||
|
latest_release = response.json()
|
||||||
|
else:
|
||||||
|
message = response.json().get("message")
|
||||||
|
print("Error fetching recent release!")
|
||||||
|
if message is not None and message.startswith("API rate limit exceeded"):
|
||||||
|
print("GitHub Rate limit exceeded. Please try again later within 1 hour or use different network/VPN.")
|
||||||
|
else:
|
||||||
|
print("Unexpected status code:", response.status_code)
|
||||||
|
return False
|
||||||
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout,
|
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout,
|
||||||
requests.exceptions.RequestException, requests.exceptions.HTTPError) as err:
|
requests.exceptions.RequestException, requests.exceptions.HTTPError) as err:
|
||||||
print ("Error Connecting to server!")
|
print("Error Connecting to server!")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
latest_version = latest_release["tag_name"]
|
latest_version = latest_release.get("tag_name")
|
||||||
|
|
||||||
# Get the current version of auto-cpufreq
|
if latest_version is not None:
|
||||||
# Extract version number from the output string
|
# Get the current version of auto-cpufreq
|
||||||
output = check_output(['auto-cpufreq', '--version']).decode('utf-8')
|
# Extract version number from the output string
|
||||||
try:
|
output = check_output(['auto-cpufreq', '--version']).decode('utf-8')
|
||||||
version_line = next((re.search(r'\d+\.\d+\.\d+', line).group() for line in output.split('\n') if line.startswith('auto-cpufreq version')), None)
|
try:
|
||||||
except AttributeError:
|
version_line = next((re.search(r'\d+\.\d+\.\d+', line).group() for line in output.split('\n') if line.startswith('auto-cpufreq version')), None)
|
||||||
print("Error Retrieving Current Version!")
|
except AttributeError:
|
||||||
exit(1)
|
print("Error Retrieving Current Version!")
|
||||||
installed_version = "v" + version_line
|
exit(1)
|
||||||
#Check whether the same is installed or not
|
installed_version = "v" + version_line
|
||||||
# Compare the latest version with the installed version and perform update if necessary
|
#Check whether the same is installed or not
|
||||||
if latest_version == installed_version:
|
# Compare the latest version with the installed version and perform update if necessary
|
||||||
print("auto-cpufreq is up to date")
|
if latest_version == installed_version:
|
||||||
return False
|
print("auto-cpufreq is up to date")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
print(f"Updates are available,\nCurrent version: {installed_version}\nLatest version: {latest_version}")
|
||||||
|
print("Note that your previous custom settings might be erased with the following update")
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
print(f"Updates are available,\nCurrent version: {installed_version}\nLatest version: {latest_version}")
|
# Handle the case where "tag_name" key doesn't exist
|
||||||
print("Note that your previous custom settings might be erased with the following update")
|
print("Malformed Released data!\nReinstall manually or Open an issue on GitHub for help!")
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def new_update(custom_dir):
|
def new_update(custom_dir):
|
||||||
os.chdir(custom_dir)
|
os.chdir(custom_dir)
|
||||||
|
|
Loading…
Reference in New Issue