Commit a21bf6f2 authored by Pierre Dittgen's avatar Pierre Dittgen

Home page: better handle catalog errors

parent f1cd967c
......@@ -46,12 +46,7 @@ class SchemaCatalogRegistry:
ref = self.ref_map.get(name)
if not ref:
return None
try:
catalog = opendataschema.SchemaCatalog(ref, session=self.session)
except requests.exceptions.RequestException as exc:
log.exception(exc)
return None
return catalog
return opendataschema.SchemaCatalog(ref, session=self.session)
caching_session = cachecontrol.CacheControl(requests.Session())
......
......@@ -27,6 +27,16 @@
</div>
</form>
</div>
{% elif section.err %}
<div class="my-5">
<h2>{{ section.title }}</h2>
{% if section.description %}
<p class="text-muted">{{ section.description }}</p>
{% endif %}
<div class="alert alert-danger" role="alert">
Catalogue indisponible : {{ section.err }}
</div>
</div>
{% endif %}
{% endfor %}
......
......@@ -71,9 +71,13 @@ class SchemaInstance:
self.section_title = self.find_section_title(self.section_name)
# Look for schema catalog first
table_schema_catalog = get_schema_catalog(self.section_name)
try:
table_schema_catalog = get_schema_catalog(self.section_name)
except Exception as ex:
log.exception(ex)
abort(400, "Erreur de traitement du catalogue")
if table_schema_catalog is None:
abort(400, "Section '{}' non trouvée dans la configuration".format(self.section_name))
abort(400, "Catalogue indisponible")
schema_reference = table_schema_catalog.reference_by_name.get(self.name)
if schema_reference is None:
......@@ -439,8 +443,18 @@ def home():
for section in config.HOMEPAGE_CONFIG['sections']:
home_section = {k: v for k, v in section.items() if k != 'catalog'}
if "catalog" in section:
schema_catalog = get_schema_catalog(section['name'])
if schema_catalog:
try:
schema_catalog = get_schema_catalog(section['name'])
except Exception as exc:
log.exception(exc)
err_msg = "une erreur s'est produite"
if isinstance(exc, requests.ConnectionError):
err_msg = "problème de connexion"
elif isinstance(exc, json.decoder.JSONDecodeError):
err_msg = "format JSON incorrect"
home_section['err'] = err_msg
else:
home_section_catalog = []
for schema_reference in schema_catalog.references:
# Loads default table schema for each schema reference
......@@ -450,6 +464,7 @@ def home():
"title": table_schema.descriptor.get("title") or schema_reference.name,
})
home_section['catalog'] = home_section_catalog
if "links" in section:
home_section["links"] = section["links"]
yield home_section
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment