Show better Google Drive error messages on MMK. (#11664)

This commit is contained in:
Alessandro Jean 2022-04-29 19:42:07 -03:00 committed by GitHub
parent 10aaeb245e
commit 9369caa588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 6 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Mundo Mangá-Kun' extName = 'Mundo Mangá-Kun'
pkgNameSuffix = 'pt.mundomangakun' pkgNameSuffix = 'pt.mundomangakun'
extClass = '.MundoMangaKun' extClass = '.MundoMangaKun'
extVersionCode = 7 extVersionCode = 8
isNsfw = true isNsfw = true
} }

View File

@ -150,12 +150,17 @@ class MundoMangaKun : ParsedHttpSource() {
val firstPageRequest = imageRequest(firstPage) val firstPageRequest = imageRequest(firstPage)
client.newCall(firstPageRequest).execute().use { client.newCall(firstPageRequest).execute().use {
it.headers["Content-Type"]!!.contains("text/html") val isHtml = it.headers["Content-Type"]!!.contains("text/html")
GoogleDriveResponse(!isHtml && it.isSuccessful, it.code)
} }
} }
if (hasExceededViewLimit.getOrDefault(false)) { val defaultResponse = GoogleDriveResponse(false, GD_BACKEND_ERROR)
throw Exception(EXCEEDED_GOOGLE_DRIVE_VIEW_LIMIT) val googleDriveResponse = hasExceededViewLimit.getOrDefault(defaultResponse)
if (!googleDriveResponse.isValid) {
throw Exception(googleDriveResponse.errorMessage)
} }
return pageList return pageList
@ -255,11 +260,25 @@ class MundoMangaKun : ParsedHttpSource() {
else -> SManga.UNKNOWN else -> SManga.UNKNOWN
} }
private data class GoogleDriveResponse(val isValid: Boolean, val code: Int) {
val errorMessage: String
get() = when (code) {
GD_SHARING_RATE_LIMIT_EXCEEDED -> EXCEEDED_GOOGLE_DRIVE_VIEW_LIMIT
else -> GOOGLE_DRIVE_UNAVAILABLE
}
}
companion object { companion object {
private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36" "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36"
private const val EXCEEDED_GOOGLE_DRIVE_VIEW_LIMIT = "Limite de visualizações atingido " + private const val EXCEEDED_GOOGLE_DRIVE_VIEW_LIMIT = "Limite de visualizações atingido " +
"no Google Drive. Aguarde com que o limite seja reestabelecido." "no Google Drive. Tente novamente mais tarde."
private const val GOOGLE_DRIVE_UNAVAILABLE = "O Google Drive está indisponível no " +
"momento. Tente novamente mais tarde."
// Reference: https://developers.google.com/drive/api/guides/handle-errors
private const val GD_SHARING_RATE_LIMIT_EXCEEDED = 403
private const val GD_BACKEND_ERROR = 500
} }
} }