Fix User Agent block error not showing at Tsuki (#8381)

* Fix UA error not showing at Tsuki.

* Add missing HTTP code in if.
This commit is contained in:
Alessandro Jean 2021-08-03 13:15:09 -03:00 committed by GitHub
parent 94915eeb0f
commit 0fb6bc0d44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Tsuki Mangás'
pkgNameSuffix = 'pt.tsukimangas'
extClass = '.TsukiMangas'
extVersionCode = 23
extVersionCode = 24
libVersion = '1.2'
containsNsfw = true
}

View File

@ -375,6 +375,12 @@ class TsukiMangas : HttpSource(), ConfigurableSource {
throw IOException(ERROR_CANNOT_LOGIN)
}
// API returns 403 or 1020 when User-Agent permission is disabled.
if (loginResponse.code == 403 || loginResponse.code == 1020) {
loginResponse.close()
throw IOException(UA_DISABLED_MESSAGE)
}
try {
val loginResponseBody = loginResponse.body?.string().orEmpty()
val authResult = json.decodeFromString<TsukiAuthResultDto>(loginResponseBody)
@ -394,11 +400,10 @@ class TsukiMangas : HttpSource(), ConfigurableSource {
val response = chain.proceed(authorizedRequest)
// API returns 403 when User-Agent permission is disabled
// and returns 401 when the token is invalid.
if (response.code == 403 || response.code == 401) {
// API returns 401 when the token is invalid.
if (response.code == 401) {
response.close()
throw IOException(if (response.code == 403) UA_DISABLED_MESSAGE else ERROR_INVALID_TOKEN)
throw IOException(ERROR_INVALID_TOKEN)
}
return response