diff --git a/src/main/scala/dpla/ingestion3/harvesters/oai/refactor/OaiMultiPageResponseBuilder.scala b/src/main/scala/dpla/ingestion3/harvesters/oai/refactor/OaiMultiPageResponseBuilder.scala index f61864e3a..92e461480 100644 --- a/src/main/scala/dpla/ingestion3/harvesters/oai/refactor/OaiMultiPageResponseBuilder.scala +++ b/src/main/scala/dpla/ingestion3/harvesters/oai/refactor/OaiMultiPageResponseBuilder.scala @@ -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 @@ -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 }