Add informative error for unapproved MAL titles (#3155)
MAL has a concept of "titles waiting for approval". These titles cannot be added to user lists, but they do show up on the website and crucially, in search results. However, trying to add such an "unapproved" title will return a 400 error response with the error "invalid_content". Previously, the awaitSuccess() call would mean the generic "HTTP 400" toast would be shown. Now, a dedicated informative error message is shown instead. # Conflicts: # CHANGELOG.md
This commit is contained in:
@@ -14,7 +14,9 @@ import eu.kanade.tachiyomi.data.track.myanimelist.dto.MALSearchResult
|
||||
import eu.kanade.tachiyomi.data.track.myanimelist.dto.MALUser
|
||||
import eu.kanade.tachiyomi.network.DELETE
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.HttpException
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.network.await
|
||||
import eu.kanade.tachiyomi.network.awaitSuccess
|
||||
import eu.kanade.tachiyomi.network.parseAs
|
||||
import eu.kanade.tachiyomi.util.PkceUtil
|
||||
@@ -124,8 +126,23 @@ class MyAnimeListApi(
|
||||
.put(formBodyBuilder.build())
|
||||
.build()
|
||||
with(json) {
|
||||
authClient.newCall(request)
|
||||
.awaitSuccess()
|
||||
val response = authClient
|
||||
.newCall(request)
|
||||
.await()
|
||||
|
||||
if (!response.isSuccessful) {
|
||||
if (response.body.string().contains("invalid_content")) {
|
||||
// MAL returns unapproved titles in search but does not allow adding them to the list
|
||||
// returns 400 with this body: {"message":"Invalid content","error":"invalid_content"}
|
||||
// These unapproved titles cannot be filtered out in search and are also returned by the
|
||||
// endpoint we use for id prefix search
|
||||
throw MALTitleNotApproved()
|
||||
} else {
|
||||
throw HttpException(response.code)
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
.parseAs<MALListItemStatus>()
|
||||
.let { parseMangaItem(it, track) }
|
||||
}
|
||||
|
||||
@@ -80,5 +80,6 @@ class MyAnimeListInterceptor(private val myanimelist: MyAnimeList) : Interceptor
|
||||
}
|
||||
}
|
||||
|
||||
class MALTitleNotApproved : IOException("MAL: This title can't be added because it is waiting for approval.")
|
||||
class MALTokenRefreshFailed : IOException("MAL: Failed to refresh account token")
|
||||
class MALTokenExpired : IOException("MAL: Login has expired")
|
||||
|
||||
Reference in New Issue
Block a user