diff --git a/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt b/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt index f630f9e5..e9983c7b 100644 --- a/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt +++ b/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt @@ -60,24 +60,26 @@ class WaccaServer(val rp: WaccaRepos, val cardRepo: CardRepository) { /** Handle all requests */ @API("/api/**") - fun handle(req: HttpServletRequest, @RB body: String) = try { - val path = req.requestURI.removePrefix("/g/wacca").removePrefix("/api").removePrefix("/").lowercase() - if (path in cacheMap) return resp(cacheMap[path]!!) - if (path !in handlerMap) return resp("[]", 1, "Not Found") + fun handle(req: HttpServletRequest, @RB body: String): Any { + return try { + val path = req.requestURI.removePrefix("/g/wacca").removePrefix("/api").removePrefix("/").lowercase() + if (path in cacheMap) return resp(cacheMap[path]!!) + if (path !in handlerMap) return resp("[]", 1, "Not Found") - log.info("Wacca < $path : $body") + log.info("Wacca < $path : $body") - val br = JACKSON.parse(body) - handlerMap[path]!!(br, br.params).let { when (it) { - is String -> return resp(it) - is List<*> -> return resp(it.toJson()) - else -> Error("Invalid response type ${it.javaClass}") - } }.let { log.info("Wacca > $path : $it") } - } - catch (e: ApiException) { resp("[]", e.code, e.message ?: "") } - catch (e: Exception) { - log.error("Wacca > Error", e) - resp("[]", 500, e.message ?: "") + val br = JACKSON.parse(body) + handlerMap[path]!!(br, br.params).let { when (it) { + is String -> return resp(it) + is List<*> -> return resp(it.toJson()) + else -> Error("Invalid response type ${it.javaClass}") + } }.let { log.info("Wacca > $path : $it") } + } + catch (e: ApiException) { resp("[]", e.code, e.message ?: "") } + catch (e: Exception) { + log.error("Wacca > Error", e) + resp("[]", 500, e.message ?: "") + } } }