From: Michael Tremer Date: Mon, 4 Mar 2024 12:51:09 +0000 (+0000) Subject: backend: Catch exception if an invalid country code was given X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=29772edccd2165a2887d934d72cb9d1bbcfbb58d;p=ipfire.org.git backend: Catch exception if an invalid country code was given Signed-off-by: Michael Tremer --- 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)