Add cloudflare detection

This commit is contained in:
Mikołaj Pich 2023-03-07 00:02:10 +01:00
parent f87dd17bae
commit 5e02645dd3
2 changed files with 5 additions and 1 deletions

View file

@ -84,6 +84,9 @@ class ErrorInterceptor(
throw ScrapperException(doc.select("#MainDiv > div").text())
}
"Połączenie zablokowane" -> throw ConnectionBlockedException(doc.body().text())
"Just a moment..." -> if (doc.select(".footer").text().contains("Cloudflare")) {
throw ConnectionBlockedException(doc.select("#challenge-body-text").text())
}
"Przerwa techniczna" -> throw ServiceUnavailableException(doc.title())
"Strona nie została odnaleziona" -> throw ScrapperException(doc.title())
"Strona nie znaleziona" -> throw ScrapperException(doc.selectFirst("div div")?.text().orEmpty())

View file

@ -17,7 +17,8 @@ class HttpErrorInterceptor : Interceptor {
return when (response.code) {
429 -> throw NotLoggedInException(response.body?.string() ?: response.message)
404 -> throw ScrapperException(response.code.toString() + ": " + response.message)
in 400..499 -> throw VulcanClientError(response.code.toString() + ": " + response.body?.string(), response.code)
in 400..402 -> throw VulcanClientError(response.code.toString() + ": " + response.body?.string(), response.code)
in 404..499 -> throw VulcanClientError(response.code.toString() + ": " + response.body?.string(), response.code)
in 500..599 -> throw ServiceUnavailableException(response.code.toString() + ": " + response.message)
else -> response
}