diff --git a/invenio_oaiharvester/errors.py b/invenio_oaiharvester/errors.py index d881b2d..fa7ab01 100644 --- a/invenio_oaiharvester/errors.py +++ b/invenio_oaiharvester/errors.py @@ -40,3 +40,7 @@ class WrongDateCombination(InvenioOAIHarvesterError): class IdentifiersOrDates(InvenioOAIHarvesterError): """Identifiers cannot be used in combination with dates.""" + + +class InvenioOAIHarvesterConfigNotFound(InvenioOAIHarvesterError): + """No InvenioOAIHarvesterConfig was found.""" diff --git a/invenio_oaiharvester/utils.py b/invenio_oaiharvester/utils.py index 0cb31ad..fd12a40 100644 --- a/invenio_oaiharvester/utils.py +++ b/invenio_oaiharvester/utils.py @@ -30,6 +30,9 @@ from flask import current_app from lxml import etree +from .errors import InvenioOAIHarvesterConfigNotFound + + REGEXP_OAI_ID = re.compile(r"(.*?)", re.DOTALL) @@ -140,7 +143,14 @@ def get_oaiharvest_object(name): :return: The OAIHarvestConfig object. """ from .models import OAIHarvestConfig - return OAIHarvestConfig.query.filter_by(name=name).first() + obj = OAIHarvestConfig.query.filter_by(name=name).first() + if not obj: + raise InvenioOAIHarvesterConfigNotFound( + 'Unable to find OAIHarvesterConfig obj with name %s.' + % name + ) + + return obj def check_or_create_dir(output_dir):