Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Error handling for popular/latest api if pageNum was supplied as zero #424

Merged
merged 3 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ object MangaList {
}

suspend fun getMangaList(sourceId: Long, pageNum: Int = 1, popular: Boolean): PagedMangaListDataClass {
/*
* Page < 0 is a invalid index in the Tachiyomi api,
* depending on the source, it can error or duplicate results to the next page.
* Hence, handling it explicitly below
* */
require(pageNum > 0) {
"Page 0 is an invalid index"
}
val source = getCatalogueSourceOrStub(sourceId)
val mangasPage = if (popular) {
source.fetchPopularManga(pageNum).awaitSingle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import suwayomi.tachidesk.manga.MangaAPI
import suwayomi.tachidesk.server.util.Browser
import suwayomi.tachidesk.server.util.setupWebInterface
import java.io.IOException
import java.lang.IllegalArgumentException
import java.util.concurrent.CompletableFuture
import kotlin.concurrent.thread

Expand Down Expand Up @@ -97,6 +98,12 @@ object JavalinSetup {
ctx.result(e.message ?: "Internal Server Error")
}

app.exception(IllegalArgumentException::class.java) { e, ctx ->
logger.error("IllegalArgumentException while handling the request", e)
ctx.status(400)
ctx.result(e.message ?: "Bad Request")
}

app.routes {
path("api/v1/") {
GlobalAPI.defineEndpoints()
Expand Down