]> git.ipfire.org Git - ipfire.org.git/commitdiff
backend: Catch exception if an invalid country code was given
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 4 Mar 2024 12:51:09 +0000 (12:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 4 Mar 2024 12:51:09 +0000 (12:51 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/base.py

index 9f013f906423e809378a1a7da9354aa077b696db..a3daa358c0ab4eb86489c48d72f74ed41faf9043 100644 (file)
@@ -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)