From 29772edccd2165a2887d934d72cb9d1bbcfbb58d Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 4 Mar 2024 12:51:09 +0000 Subject: [PATCH] backend: Catch exception if an invalid country code was given Signed-off-by: Michael Tremer --- src/backend/base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backend/base.py b/src/backend/base.py index 9f013f90..a3daa358 100644 --- a/src/backend/base.py +++ b/src/backend/base.py @@ -209,11 +209,18 @@ class Backend(object): return location.Database("/var/lib/location/database.db") def get_country_name(self, country_code): - country = self.location.get_country(country_code) + try: + country = self.location.get_country(country_code) + + # In case the country code was invalid, we return it again + except ValueError: + return country_code if country: return country.name + return country_code + @lazy_property def ratelimiter(self): return ratelimit.RateLimiter(self) -- 2.47.3