diff --git a/ckanext/odsh/validation.py b/ckanext/odsh/validation.py
index 14151edb6910e859fd6f7294376f70af70805f55..c850252966e648148639e25a7c671e7951550370 100644
--- a/ckanext/odsh/validation.py
+++ b/ckanext/odsh/validation.py
@@ -2,7 +2,9 @@
 import logging
 import csv
 import re
-import urllib.request, urllib.error, urllib.parse
+import urllib.request
+import urllib.error
+import urllib.parse
 import json
 import ckan.logic as logic
 
@@ -69,27 +71,28 @@ def validate_extra_groups(data, requireAtLeastOne, errors):
 def validate_extras(key, data, errors, context):
     log.debug("Validating extras")
     extra_errors = {}
-    
+
     isStaNord = ('id',) in data and data[('id',)][:7] == 'StaNord'
-    harvesting = ('ignore_auth' in context) and (context['ignore_auth'] == True)
+    harvesting = ('ignore_auth' in context) and (
+        context['ignore_auth'] == True)
     owner_org = data[('owner_org',)]
-    lenient_with = tk.config.get('ckanext.odsh.lenient_with','')
+    lenient_with = tk.config.get('ckanext.odsh.lenient_with', '')
 
     is_optional_temporal_start = toolkit.asbool(
         tk.config.get('ckanext.odsh.is_optional_temporal_start', False)
-    ) or ( harvesting and (owner_org in lenient_with) )
+    ) or (harvesting and (owner_org in lenient_with))
 
     require_at_least_one_category = toolkit.asbool(
         tk.config.get('ckanext.odsh.require_at_least_one_category', False)
     )
     validate_extra_groups(
-        data=data, 
-        requireAtLeastOne=require_at_least_one_category, 
+        data=data,
+        requireAtLeastOne=require_at_least_one_category,
         errors=extra_errors
     )
-    
+
     is_date_start_before_date_end(data, extra_errors)
-    
+
     validate_extra_date_new(
         key=key,
         field='issued',
@@ -101,7 +104,7 @@ def validate_extras(key, data, errors, context):
         key=key,
         field='temporal_start',
         data=data,
-        optional=is_optional_temporal_start, 
+        optional=is_optional_temporal_start,
         errors=extra_errors
     )
     validate_extra_date_new(
@@ -115,6 +118,7 @@ def validate_extras(key, data, errors, context):
     if len(list(extra_errors.values())):
         raise toolkit.Invalid(extra_errors)
 
+
 def is_date_start_before_date_end(data, extra_errors):
     start_date = _extract_value(data, 'temporal_start')
     end_date = _extract_value(data, 'temporal_end')
@@ -122,6 +126,7 @@ def is_date_start_before_date_end(data, extra_errors):
         if start_date > end_date:
             extra_errors['temporal_start'] = extra_errors['temporal_end'] = 'Please enter a valid period of time.'
 
+
 def _set_value(data, field, value):
     key = None
     for k in list(data.keys()):
@@ -209,7 +214,7 @@ def known_spatial_uri(key, data, errors, context):
                 poly = pkg.extras.get('spatial', None)
         if (not poly) and require_spatial_uri:
             raise toolkit.Invalid(error_message_spatial_uri_empty)
-        #if has_old_uri and require_spatial_uri:
+        # if has_old_uri and require_spatial_uri:
         #    raise toolkit.Invalid(error_message_spatial_uri_empty)
         else:
             if poly:
@@ -219,23 +224,28 @@ def known_spatial_uri(key, data, errors, context):
             return
 
     extension_path = pkg_resources.resource_filename('ckanext.odsh', '')
-    mapping_path = tk.config.get('ckanext.odsh.spatial.mapping', extension_path + '/resources/schleswig-holstein_geojson.csv')
+    mapping_path = tk.config.get('ckanext.odsh.spatial.mapping',
+                                 extension_path + '/resources/schleswig-holstein_geojson.csv')
 
     not_found = True
     spatial_text = str()
     spatial = str()
-    with open(mapping_path, newline='') as mapping_file:
-      cr = csv.reader(mapping_file, delimiter="\t")
-      for row in cr:
-        if row[0] == value:
-            not_found = False
-            spatial_text = row[1]
-            loaded = json.loads(row[2])
-            spatial = json.dumps(loaded['geometry'])
-            break
-      if not_found:
-        raise toolkit.Invalid(
-            'spatial_uri: uri unknown')
+
+    try:
+        with open(mapping_path, newline='') as mapping_file:
+            cr = csv.reader(mapping_file, delimiter="\t")
+            for row in cr:
+                if row and len(row) > 2 and row[0] == value:
+                    not_found = False
+                    spatial_text = row[1]
+                    loaded = json.loads(row[2])
+                    spatial = json.dumps(loaded.get('geometry', {}))
+                    break
+            if not_found:
+                raise toolkit.Invalid('spatial_uri: uri unknown')
+    except (IOError, json.decoder.JSONDecodeError, KeyError) as e:
+        log.error(f"Error processing spatial mapping: {e}")
+        raise toolkit.Invalid("Error processing spatial mapping")
 
     new_index = next_extra_index(data)
 
@@ -261,7 +271,7 @@ def _copy_spatial_uri_temp_to_extras(data):
         data[('extras', next_index, 'value')] = spatial_uri
     else:
         _set_value(data, 'spatial_uri', spatial_uri)
-    
+
 
 def next_extra_index(data):
     current_indexes = [k[1] for k in list(data.keys())
@@ -275,7 +285,8 @@ def validate_relatedPackage(data):
         try:
             get_package_dict(data)
         except logic.NotFound:
-            raise toolkit.Invalid("relatedPackage: package '{}' not found".format(data))
+            raise toolkit.Invalid(
+                "relatedPackage: package '{}' not found".format(data))
 
 
 def validate_formats(data, errors):
@@ -283,7 +294,8 @@ def validate_formats(data, errors):
         raise toolkit.Invalid('Missing format.')
 
     if not any(data.upper() == obj['key'] for obj in odsh_resource_formats()):
-        raise toolkit.Invalid(_('Only formats on the list of the EU Publications Office are allowed.'))
+        raise toolkit.Invalid(
+            _('Only formats on the list of the EU Publications Office are allowed.'))
 
     return data
 
@@ -293,7 +305,8 @@ def tag_name_validator(value, context):
     """
     tagname_match = re.compile(r'^(?=.*[^\n])[^\n]*$', re.UNICODE)
     if not tagname_match.match(value):
-        raise toolkit.Invalid(_('Invalid tag: "%s". Tags cannot contain line breaks.') % (value))
+        raise toolkit.Invalid(
+            _('Invalid tag: "%s". Tags cannot contain line breaks.') % (value))
     return value
 
 
@@ -302,7 +315,7 @@ def get_validators():
         'known_spatial_uri': known_spatial_uri,
         'odsh_validate_extras': validate_extras,
         'validate_licenseAttributionByText': validate_licenseAttributionByText,
-	      'validate_relatedPackage': validate_relatedPackage,
+        'validate_relatedPackage': validate_relatedPackage,
         'odsh_validate_format': validate_formats,
         'tag_name_validator': tag_name_validator,
     }