diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/MangaList.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/MangaList.kt index 1bea6eec..7f19b2c4 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/MangaList.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/MangaList.kt @@ -27,6 +27,9 @@ object MangaList { } 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 mangasPage = if (popular) { source.fetchPopularManga(pageNum).awaitSingle() diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt index 4d943345..7ccce731 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/JavalinSetup.kt @@ -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 @@ -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()