Show a better error message when Cloudflare is on at AS. (#9887)

This commit is contained in:
Alessandro Jean 2021-11-21 20:40:37 -03:00 committed by GitHub
parent 190d406ef0
commit d186bacf98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Argos Scan'
pkgNameSuffix = 'pt.argosscan'
extClass = '.ArgosScan'
extVersionCode = 17
extVersionCode = 18
}
dependencies {

View File

@ -294,6 +294,13 @@ class ArgosScan : HttpSource(), ConfigurableSource {
if (!email.isNullOrEmpty() && !password.isNullOrEmpty() && token.isNullOrEmpty()) {
val loginResponse = chain.proceed(loginRequest(email, password))
if (!loginResponse.headers["Content-Type"].orEmpty().contains("application/json")) {
loginResponse.close()
throw IOException(CLOUDFLARE_ERROR)
}
val loginResult = json.parseToJsonElement(loginResponse.body!!.string()).jsonObject
if (loginResult["errors"] != null) {
@ -356,6 +363,7 @@ class ArgosScan : HttpSource(), ConfigurableSource {
private const val PASSWORD_PREF_SUMMARY = "Defina a senha de sua conta no site."
private const val PASSWORD_PREF_DIALOG = EMAIL_PREF_DIALOG
private const val CLOUDFLARE_ERROR = "Falha ao contornar o Cloudflare."
private const val REQUEST_ERROR = "Erro na requisição. Tente novamente mais tarde."
private val JSON_MEDIA_TYPE = "application/json; charset=utf-8".toMediaTypeOrNull()