Skip to content

Commit

Permalink
Fix code scanning alert no. 7: Information exposure through an exception
Browse files Browse the repository at this point in the history
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 986f1f0 commit 64fec50
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions apps/python-geoweather/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def get_public_ip():
return response.text.strip()
except requests.HTTPError as http_err:
logging.error(f'HTTP error occurred: {http_err}') # HTTP error
return f"Unable to get public IP: HTTP error occurred: {http_err}"
return "Unable to get public IP due to an internal error."
except Exception as err:
logging.error(f'Other error occurred: {err}') # Other errors
return f"Unable to get public IP: Other error occurred: {err}"
return "Unable to get public IP due to an internal error."

def get_location(ip):
url = f"https://ipwho.is/{ip}?fields=country,city,latitude,longitude"
Expand All @@ -27,10 +27,10 @@ def get_location(ip):
return response.json()
except requests.HTTPError as http_err:
logging.error(f'HTTP error occurred while fetching location: {http_err}')
return {'error': f"HTTP error occurred: {http_err}"}
return {'error': "Unable to fetch location due to an internal error."}
except Exception as err:
logging.error(f'Error fetching location: {err}')
return {'error': f"Other error occurred: {err}"}
return {'error': "Unable to fetch location due to an internal error."}

def get_weather(lat, lon):
url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current=temperature_2m&forecast_days=1"
Expand All @@ -40,10 +40,10 @@ def get_weather(lat, lon):
return response.json()
except requests.HTTPError as http_err:
logging.error(f'HTTP error occurred while fetching weather: {http_err}')
return {'error': f"HTTP error occurred: {http_err}"}
return {'error': "Unable to fetch weather due to an internal error."}
except Exception as err:
logging.error(f'Error fetching weather: {err}')
return {'error': f"Other error occurred: {err}"}
return {'error': "Unable to fetch weather due to an internal error."}

@app.route('/')
def index():
Expand Down

0 comments on commit 64fec50

Please sign in to comment.