Overhaul error handling

This commit is contained in:
Marius Alwan Meyer 2023-09-29 13:37:47 +02:00
parent 20a153e857
commit f1ce9fb455

View File

@ -15,30 +15,31 @@ response = requests.get(complete_url)
data = response.json() data = response.json()
if response.status_code == 200: print()
match response.status_code:
case 200:
info_main = data["main"]
info_weather = data["weather"]
current_temperature = info_main["temp"]
current_pressure = info_main["pressure"]
current_humidity = info_main["humidity"]
weather_description = info_weather[0]["description"]
info_main = data["main"] print(Columns([
info_weather = data["weather"] Panel(f"[blue]{round(current_temperature - 273.15, 2)}°C",
current_temperature = info_main["temp"] title="[bold]Temperature[/bold]"),
current_pressure = info_main["pressure"]
current_humidity = info_main["humidity"]
weather_description = info_weather[0]["description"]
print() Panel(f"[blue]{current_pressure}hPa",
print(Columns([ title="[bold]Atmospheric Pressure[/bold]"),
Panel(f"[blue]{round(current_temperature - 273.15, 2)}°C",
title="[bold]Temperature[/bold]"),
Panel(f"[blue]{current_pressure}hPa", Panel(f"[blue]{current_humidity}%",
title="[bold]Atmospheric Pressure[/bold]"), title="[bold]Humidity[/bold]"),
Panel(f"[blue]{current_humidity}%", Panel(f"[blue]{weather_description}",
title="[bold]Humidity[/bold]"), title="[bold]Description[/bold]"),
]))
Panel(f"[blue]{weather_description}", case _:
title="[bold]Description[/bold]"), print(Panel(data["message"],
])) title=f"[bold red]Error: {response.status_code}",
expand=False))
else:
print(f"Fehler: {response.status_code}")
print(response.text)