From 69c0703e17784864474d0d41ee4edac0fdb02e85 Mon Sep 17 00:00:00 2001 From: Marius Alwan Meyer Date: Fri, 29 Sep 2023 13:41:35 +0200 Subject: [PATCH] Handle errors when there was no json response --- openweather.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/openweather.py b/openweather.py index ec2c976..1dfdf31 100755 --- a/openweather.py +++ b/openweather.py @@ -40,6 +40,11 @@ match response.status_code: ])) case _: - print(Panel(data["message"], - title=f"[bold red]Error: {response.status_code}", - expand=False)) + if "message" in data: + print(Panel(data["message"], + title=f"[bold red]Error: {response.status_code}", + expand=False)) + else: + print(Panel("unknown error", + title=f"[bold red]Error: {response.status_code}", + expand=False))