Skip to content

Commit

Permalink
Fixed iteration.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellabitta committed Dec 4, 2024
1 parent 3c240f1 commit e19742a
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@ class OaiMultiPageResponseBuilder(
new Iterable[OaiPage] {
override def iterator: Iterator[OaiPage] = new Iterator[OaiPage]() {

def handleErrors(eitherResponse: Either[OaiError, OaiPage]): Option[OaiPage] = eitherResponse match {
def handleErrors(eitherResponse: Either[OaiError, OaiPage], url: URL): Option[OaiPage] = eitherResponse match {
case Left(error) =>
error match {
case NoRecordsMatch() =>
None // Not an error that should interrupt execution.
case _ =>
throw new RuntimeException(s"OAI Error: $error")
throw new RuntimeException(s"OAI Error: $error for $url")
}
case Right(page) =>
Some(page)
}

var onDeck: Option[OaiPage] = handleErrors(getSinglePage(buildUrl()))
var onDeck: Option[OaiPage] = {
val url = buildUrl()
handleErrors(getSinglePage(url), url)
}


override def hasNext: Boolean = onDeck.isDefined
Expand All @@ -57,7 +60,7 @@ class OaiMultiPageResponseBuilder(
case None => onDeck = None
case Some(tokenValue) =>
val url = buildUrl(Some(tokenValue))
handleErrors(getSinglePage(url))
onDeck = handleErrors(getSinglePage(url), url)
}
last
}
Expand Down

0 comments on commit e19742a

Please sign in to comment.