Skip to content
Snippets Groups Projects
Commit 66422776 authored by gabriele-h's avatar gabriele-h
Browse files

Raise exception if >10k records

parent 536ce03b
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,10 @@ class NotUnique(SruException):
pass
class TooManyRecords(SruException):
pass
class SruDiagnostics(SruException):
pass
......@@ -111,6 +115,7 @@ class RecordRetriever:
num_recs = sru_xml.find("srw:numberOfRecords", self.namespaces)
self._raise_error_no_match(num_recs)
self._raise_error_sru(sru_xml)
self._raise_error_too_many_recs(num_recs)
num_pages = int(num_recs.text)//10
......@@ -121,6 +126,8 @@ class RecordRetriever:
startrecord = (i+1)*10+1
sru_url = self._create_url(alma_query, startrecord)
sru_xml = self._response_to_xml(sru_url)
self._raise_error_sru()
xml_list.extend(self._extract_marc_xml(sru_xml))
return xml_list
......@@ -147,16 +154,23 @@ class RecordRetriever:
def _raise_error_unique(num_recs: Element):
if (num_recs is not None and
num_recs.text > '1'):
int(num_recs.text) > 1):
raise NotUnique('More than one record found'
'while exactly one was expected!')
'while exactly one was expected.')
@staticmethod
def _raise_error_no_match(num_recs: Element):
if (num_recs is not None and
num_recs.text == '0'):
raise NoRecord('No matching records found!')
raise NoRecord('No matching records found.')
@staticmethod
def _raise_error_too_many_recs(num_recs: Element):
if int(num_recs.text) > 10000:
raise TooManyRecords('SRU searches are limited to 10.000 '
'records.')
def _raise_error_sru(self, sru_xml: Element):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment