Add workaround for 'Login Service' page errors
This commit is contained in:
parent
a0572e7743
commit
c9005720c9
3 changed files with 11 additions and 4 deletions
|
@ -14,8 +14,11 @@ import okhttp3.Response
|
|||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.net.CookieManager
|
||||
|
||||
class ErrorInterceptor : Interceptor {
|
||||
class ErrorInterceptor(
|
||||
private val cookies: CookieManager,
|
||||
) : Interceptor {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
|
@ -75,7 +78,11 @@ class ErrorInterceptor : Interceptor {
|
|||
"Błąd" -> throw VulcanException(doc.body().text())
|
||||
"Błąd strony" -> throw VulcanException(doc.select(".errorMessage").text())
|
||||
"Logowanie" -> throw AccountPermissionException(doc.select("div").last()?.ownText().orEmpty().split(" Jeśli")[0])
|
||||
"Login Service" -> throw ScrapperException(doc.select("#MainDiv > div").text())
|
||||
"Login Service" -> {
|
||||
cookies.cookieStore.removeAll() // workaround for very strange (random) errors
|
||||
throw ScrapperException(doc.select("#MainDiv > div").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())
|
||||
|
|
|
@ -82,7 +82,7 @@ class ServiceManager(
|
|||
|
||||
private val interceptors: MutableList<Pair<Interceptor, Boolean>> = mutableListOf(
|
||||
HttpLoggingInterceptor().setLevel(logLevel) to true,
|
||||
ErrorInterceptor() to false,
|
||||
ErrorInterceptor(cookies) to false,
|
||||
AutoLoginInterceptor(loginType, cookies, emptyCookieJarIntercept) { loginHelper.login(email, password) } to false,
|
||||
UserAgentInterceptor(androidVersion, buildTag) to false,
|
||||
HttpErrorInterceptor() to false
|
||||
|
|
|
@ -83,7 +83,7 @@ abstract class BaseLocalTest : BaseTest() {
|
|||
autoLoginInterceptor: AutoLoginInterceptor = getAutoLoginInterceptor(loginType, autoLogin)
|
||||
): OkHttpClient = OkHttpClient.Builder()
|
||||
.apply {
|
||||
if (errorInterceptor) addInterceptor(ErrorInterceptor())
|
||||
if (errorInterceptor) addInterceptor(ErrorInterceptor(cookies))
|
||||
if (autoLoginInterceptorOn) addInterceptor(autoLoginInterceptor)
|
||||
}
|
||||
.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC))
|
||||
|
|
Loading…
Reference in a new issue