From 51a477d5b9607212907cc2a73a1ee0b8c2c83825 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:24:15 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Activity=E3=81=AEType=E3=81=AE=E3=83=91?= =?UTF-8?q?=E3=83=BC=E3=82=B9=E6=99=82=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usbharu/hideout/service/ap/APService.kt | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt index 9cd1cedf..a1483b00 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt @@ -186,7 +186,11 @@ class APServiceImpl( val logger: Logger = LoggerFactory.getLogger(APServiceImpl::class.java) override fun parseActivity(json: String): ActivityType { - val readTree = objectMapper.readTree(json) + val readTree = try { + objectMapper.readTree(json) + } catch (e: com.fasterxml.jackson.core.JsonParseException) { + throw JsonParseException("Failed to parse json", e) + } logger.trace( """ | @@ -204,11 +208,19 @@ class APServiceImpl( } val type = readTree["type"] ?: throw JsonParseException("Type is null") if (type.isArray) { - return type.firstNotNullOf { jsonNode: JsonNode -> - ActivityType.values().firstOrNull { it.name.equals(jsonNode.asText(), true) } + try { + return type.firstNotNullOf { jsonNode: JsonNode -> + ActivityType.values().firstOrNull { it.name.equals(jsonNode.asText(), true) } + } + } catch (e: NoSuchElementException) { + throw IllegalArgumentException("No valid TYPE", e) } } - return ActivityType.values().first { it.name.equals(type.asText(), true) } + try { + return ActivityType.values().first { it.name.equals(type.asText(), true) } + } catch (e: NoSuchElementException) { + throw IllegalArgumentException("No valid TYPE", e) + } } @Suppress("CyclomaticComplexMethod", "NotImplementedDeclaration") @@ -219,6 +231,7 @@ class APServiceImpl( ActivityType.Follow -> apReceiveFollowService .receiveFollow(objectMapper.readValue(json, Follow::class.java)) + ActivityType.Create -> apCreateService.receiveCreate(objectMapper.readValue(json)) ActivityType.Like -> apLikeService.receiveLike(objectMapper.readValue(json)) ActivityType.Undo -> apUndoService.receiveUndo(objectMapper.readValue(json))