Koha: Improve error handling of empty/invalid search
@@ -71,6 +71,11 @@ open class Koha : OkHttpBaseApi() {
protected open fun parseSearch(doc: Document, page: Int): SearchRequestResult {
if (doc.select("#noresultsfound").first() != null) {
return SearchRequestResult(emptyList(), 0, page)
+ } else if (doc.select("select[name=idx]").first() != null) {
+ // We're back on the search page, no valid (likely empty) query
+ throw OpacApi.OpacErrorException(stringProvider.getString("no_criteria_input"))
+ } else if (doc.select("#numresults").first() == null) {
+ throw OpacApi.OpacErrorException(stringProvider.getString("unknown_error"))
}
val countText = doc.select("#numresults").first().text
