Catch more mangadex exceptions
This commit is contained in:
parent
69ddd04256
commit
aac2fcb7d4
@ -205,6 +205,7 @@ class MangaDex(delegate: HttpSource, val context: Context) :
|
|||||||
add("two_factor", twoFactorCode)
|
add("two_factor", twoFactorCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runCatching {
|
||||||
client.newCall(
|
client.newCall(
|
||||||
POST(
|
POST(
|
||||||
"${MdUtil.baseUrl}/ajax/actions.ajax.php?function=login",
|
"${MdUtil.baseUrl}/ajax/actions.ajax.php?function=login",
|
||||||
@ -212,6 +213,8 @@ class MangaDex(delegate: HttpSource, val context: Context) :
|
|||||||
formBody.build()
|
formBody.build()
|
||||||
)
|
)
|
||||||
).await().closeQuietly()
|
).await().closeQuietly()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
val response = client.newCall(GET(MdUtil.apiUrl + MdUtil.isLoggedInApi, headers)).await()
|
val response = client.newCall(GET(MdUtil.apiUrl + MdUtil.isLoggedInApi, headers)).await()
|
||||||
|
|
||||||
@ -235,10 +238,10 @@ class MangaDex(delegate: HttpSource, val context: Context) :
|
|||||||
if (token.isNullOrEmpty()) {
|
if (token.isNullOrEmpty()) {
|
||||||
return@withIOContext true
|
return@withIOContext true
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
val result = client.newCall(
|
val result = client.newCall(
|
||||||
POST("${MdUtil.baseUrl}/ajax/actions.ajax.php?function=logout", headers).newBuilder().addHeader(REMEMBER_ME, token).build()
|
POST("${MdUtil.baseUrl}/ajax/actions.ajax.php?function=logout", headers).newBuilder().addHeader(REMEMBER_ME, token).build()
|
||||||
).await()
|
).await()
|
||||||
try {
|
|
||||||
val resultStr = withIOContext { result.body?.string() }
|
val resultStr = withIOContext { result.body?.string() }
|
||||||
if (resultStr?.contains("success", true) == true) {
|
if (resultStr?.contains("success", true) == true) {
|
||||||
network.cookieManager.remove(httpUrl)
|
network.cookieManager.remove(httpUrl)
|
||||||
|
@ -23,6 +23,7 @@ import exh.util.awaitResponse
|
|||||||
import exh.util.floor
|
import exh.util.floor
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import okhttp3.CacheControl
|
import okhttp3.CacheControl
|
||||||
|
import okhttp3.Call
|
||||||
import okhttp3.FormBody
|
import okhttp3.FormBody
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@ -127,7 +128,6 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
|
|||||||
*/
|
*/
|
||||||
suspend fun updateFollowStatus(mangaID: String, followStatus: FollowStatus): Boolean {
|
suspend fun updateFollowStatus(mangaID: String, followStatus: FollowStatus): Boolean {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val response: Response =
|
|
||||||
if (followStatus == FollowStatus.UNFOLLOWED) {
|
if (followStatus == FollowStatus.UNFOLLOWED) {
|
||||||
client.newCall(
|
client.newCall(
|
||||||
GET(
|
GET(
|
||||||
@ -136,7 +136,6 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
|
|||||||
CacheControl.FORCE_NETWORK
|
CacheControl.FORCE_NETWORK
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.await()
|
|
||||||
} else {
|
} else {
|
||||||
val status = followStatus.int
|
val status = followStatus.int
|
||||||
client.newCall(
|
client.newCall(
|
||||||
@ -146,10 +145,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
|
|||||||
CacheControl.FORCE_NETWORK
|
CacheControl.FORCE_NETWORK
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.await()
|
}.succeeded()
|
||||||
}
|
|
||||||
|
|
||||||
response.succeeded()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,35 +156,31 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
|
|||||||
.add("volume", "0")
|
.add("volume", "0")
|
||||||
.add("chapter", track.last_chapter_read.toString())
|
.add("chapter", track.last_chapter_read.toString())
|
||||||
xLogD("chapter to update %s", track.last_chapter_read.toString())
|
xLogD("chapter to update %s", track.last_chapter_read.toString())
|
||||||
val response = client.newCall(
|
client.newCall(
|
||||||
POST(
|
POST(
|
||||||
"${MdUtil.baseUrl}/ajax/actions.ajax.php?function=edit_progress&id=$mangaID",
|
"${MdUtil.baseUrl}/ajax/actions.ajax.php?function=edit_progress&id=$mangaID",
|
||||||
headers,
|
headers,
|
||||||
formBody.build()
|
formBody.build()
|
||||||
)
|
)
|
||||||
).await()
|
).succeeded()
|
||||||
|
|
||||||
response.succeeded()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun updateRating(track: Track): Boolean {
|
suspend fun updateRating(track: Track): Boolean {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val mangaID = MdUtil.getMangaId(track.tracking_url)
|
val mangaID = MdUtil.getMangaId(track.tracking_url)
|
||||||
val response = client.newCall(
|
client.newCall(
|
||||||
GET(
|
GET(
|
||||||
"${MdUtil.baseUrl}/ajax/actions.ajax.php?function=manga_rating&id=$mangaID&rating=${track.score.toInt()}",
|
"${MdUtil.baseUrl}/ajax/actions.ajax.php?function=manga_rating&id=$mangaID&rating=${track.score.toInt()}",
|
||||||
headers
|
headers
|
||||||
)
|
)
|
||||||
).await()
|
).succeeded()
|
||||||
|
|
||||||
response.succeeded()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun Response.succeeded() = withIOContext {
|
private suspend fun Call.succeeded() = withIOContext {
|
||||||
try {
|
try {
|
||||||
body?.string().let { body ->
|
await().body?.string().let { body ->
|
||||||
(body != null && body.isEmpty()).also {
|
(body != null && body.isEmpty()).also {
|
||||||
if (!it) xLogD(body)
|
if (!it) xLogD(body)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user