diff --git a/src/main/kotlin/de/darkatra/vrising/discord/clients/botcompanion/BotCompanionClient.kt b/src/main/kotlin/de/darkatra/vrising/discord/clients/botcompanion/BotCompanionClient.kt index 079cdcc..ff72253 100644 --- a/src/main/kotlin/de/darkatra/vrising/discord/clients/botcompanion/BotCompanionClient.kt +++ b/src/main/kotlin/de/darkatra/vrising/discord/clients/botcompanion/BotCompanionClient.kt @@ -52,7 +52,11 @@ class BotCompanionClient( serverApiPassword: String? = null ): Result> { - val response = performRequest(getRequestUrl(serverApiHostName, serverApiPort), "/characters", serverApiUsername, serverApiPassword) + val response = try { + performRequest(getRequestUrl(serverApiHostName, serverApiPort), "/characters", serverApiUsername, serverApiPassword) + } catch (e: Exception) { + return Result.failure(BotCompanionClientException("Unexpected exception performing ${this::getCharacters.name} request.", e)) + } return when (response.status) { HttpStatusCode.OK -> Result.success(objectMapper.readValue(response.bodyAsText(), jacksonTypeRef>())) @@ -67,7 +71,11 @@ class BotCompanionClient( serverApiPassword: String? = null ): Result> { - val response = performRequest(getRequestUrl(serverApiHostName, serverApiPort), "/player-activities", serverApiUsername, serverApiPassword) + val response = try { + performRequest(getRequestUrl(serverApiHostName, serverApiPort), "/player-activities", serverApiUsername, serverApiPassword) + } catch (e: Exception) { + return Result.failure(BotCompanionClientException("Unexpected exception performing ${this::getPlayerActivities.name} request.", e)) + } return when (response.status) { HttpStatusCode.OK -> Result.success(objectMapper.readValue(response.bodyAsText(), jacksonTypeRef>())) @@ -82,7 +90,11 @@ class BotCompanionClient( serverApiPassword: String? = null ): Result> { - val response = performRequest(getRequestUrl(serverApiHostName, serverApiPort), "/pvp-kills", serverApiUsername, serverApiPassword) + val response = try { + performRequest(getRequestUrl(serverApiHostName, serverApiPort), "/pvp-kills", serverApiUsername, serverApiPassword) + } catch (e: Exception) { + return Result.failure(BotCompanionClientException("Unexpected exception performing ${this::getPvpKills.name} request.", e)) + } return when (response.status) { HttpStatusCode.OK -> Result.success(objectMapper.readValue(response.bodyAsText(), jacksonTypeRef>())) diff --git a/src/main/kotlin/de/darkatra/vrising/discord/clients/botcompanion/BotCompanionClientException.kt b/src/main/kotlin/de/darkatra/vrising/discord/clients/botcompanion/BotCompanionClientException.kt index 41c36ea..aa18cf0 100644 --- a/src/main/kotlin/de/darkatra/vrising/discord/clients/botcompanion/BotCompanionClientException.kt +++ b/src/main/kotlin/de/darkatra/vrising/discord/clients/botcompanion/BotCompanionClientException.kt @@ -2,4 +2,4 @@ package de.darkatra.vrising.discord.clients.botcompanion import de.darkatra.vrising.discord.BotException -class BotCompanionClientException(message: String) : BotException(message) +class BotCompanionClientException(message: String, cause: Throwable? = null) : BotException(message, cause)