diff --git a/CHANGES.rst b/CHANGES.rst index e24d8ac..823fb15 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,8 +5,8 @@ Changelog 1.4.1 (unreleased) ------------------ -- Nothing changed yet. - +- Raise custom exception when there is an error. + [cekk] 1.4.0 (2024-05-05) ------------------ diff --git a/src/rer/solrpush/browser/maintenance.py b/src/rer/solrpush/browser/maintenance.py index 2332699..d0b71cf 100644 --- a/src/rer/solrpush/browser/maintenance.py +++ b/src/rer/solrpush/browser/maintenance.py @@ -318,7 +318,7 @@ def sync_contents( tot = len(brains_to_sync) for brain in brains_to_sync: i += 1 - if i % 10 == 0: + if i % 100 == 0: logger.info(f"Progress: {i}/{tot}") if not disable_progress: status["counter"] = status["counter"] + 1 @@ -327,9 +327,7 @@ def sync_contents( if brain.UID not in solr_items: # missing from solr: try to index it try: - logger.info("send to solr") res = push_to_solr(item) - logger.info("received response from solr") if res: indexed.append(brain.getPath()) except SolrError as e: diff --git a/src/rer/solrpush/restapi/services/solr_search/solr_search_handler.py b/src/rer/solrpush/restapi/services/solr_search/solr_search_handler.py index 7f807ca..a69fa79 100644 --- a/src/rer/solrpush/restapi/services/solr_search/solr_search_handler.py +++ b/src/rer/solrpush/restapi/services/solr_search/solr_search_handler.py @@ -6,7 +6,6 @@ from rer.solrpush.restapi.services.solr_search.batch import SolrHypermediaBatch from rer.solrpush.utils import search as solr_search - DEFAULT_METADATA_FIELDS = set( ["@id", "@type", "description", "review_state", "title"] ) diff --git a/src/rer/solrpush/utils/solr_search.py b/src/rer/solrpush/utils/solr_search.py index d4a981e..f55f89f 100644 --- a/src/rer/solrpush/utils/solr_search.py +++ b/src/rer/solrpush/utils/solr_search.py @@ -26,6 +26,12 @@ TRIM = re.compile(r"\s+") ESCAPE_CHARS_RE = re.compile(r'(?[&|+\-!(){}[\]^"~*?:])') + +class SOLRException(Exception): + "Raised when the solr respoonse return an error" + pass + + # HELPER METHODS @@ -304,13 +310,12 @@ def search( if is_solr_active(): # log it beacuse it's misconfigured logger.error(msg) - return { - "error": True, - "message": translate( + raise SOLRException( + translate( _("solr_configuration_error_label", default=msg), context=api.portal.get().REQUEST, - ), - } + ) + ) solr_query = generate_query( query, fl=fl, @@ -323,9 +328,8 @@ def search( return res except Exception as e: logger.exception(e) - return { - "error": True, - "message": translate( + raise SOLRException( + translate( _( "search_error_label", default="Unable to perform a search with SOLR." @@ -333,8 +337,8 @@ def search( " minutes.", ), context=api.portal.get().REQUEST, - ), - } + ) + ) def _set_query_debug(solr, params):