mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-11 15:22:05 +01:00
Fix: Error handling for popular/latest api if pageNum was supplied as zero (#424)
* fix: handle and throw proper error if pageNum is zero for popular/latest api, fixes #75 * chore: replace if-else with kotlin require which throws IllegalArgumentException and add comment * fix: remove comment as exception message is enough
This commit is contained in:
@@ -27,6 +27,9 @@ object MangaList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getMangaList(sourceId: Long, pageNum: Int = 1, popular: Boolean): PagedMangaListDataClass {
|
suspend fun getMangaList(sourceId: Long, pageNum: Int = 1, popular: Boolean): PagedMangaListDataClass {
|
||||||
|
require(pageNum > 0) {
|
||||||
|
"pageNum = $pageNum is not in valid range"
|
||||||
|
}
|
||||||
val source = getCatalogueSourceOrStub(sourceId)
|
val source = getCatalogueSourceOrStub(sourceId)
|
||||||
val mangasPage = if (popular) {
|
val mangasPage = if (popular) {
|
||||||
source.fetchPopularManga(pageNum).awaitSingle()
|
source.fetchPopularManga(pageNum).awaitSingle()
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import suwayomi.tachidesk.manga.MangaAPI
|
|||||||
import suwayomi.tachidesk.server.util.Browser
|
import suwayomi.tachidesk.server.util.Browser
|
||||||
import suwayomi.tachidesk.server.util.setupWebInterface
|
import suwayomi.tachidesk.server.util.setupWebInterface
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.lang.IllegalArgumentException
|
||||||
import java.util.concurrent.CompletableFuture
|
import java.util.concurrent.CompletableFuture
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
@@ -97,6 +98,12 @@ object JavalinSetup {
|
|||||||
ctx.result(e.message ?: "Internal Server Error")
|
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 {
|
app.routes {
|
||||||
path("api/v1/") {
|
path("api/v1/") {
|
||||||
GlobalAPI.defineEndpoints()
|
GlobalAPI.defineEndpoints()
|
||||||
|
|||||||
Reference in New Issue
Block a user