From 8748a5df8778e598f73ea834e989d20808b1987c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Sv=C4=9Bceny?= Date: Thu, 9 Nov 2023 17:17:05 +0100 Subject: [PATCH] fix(associations): error exception receives wrong type --- .../hubspot/domain/associations/AssociationClient.kt | 4 ++-- .../exceptions/AssociationNotFoundException.kt | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/hubspot/src/main/kotlin/org/boomevents/hubspot/domain/associations/AssociationClient.kt b/hubspot/src/main/kotlin/org/boomevents/hubspot/domain/associations/AssociationClient.kt index bec6fd8..ec13575 100644 --- a/hubspot/src/main/kotlin/org/boomevents/hubspot/domain/associations/AssociationClient.kt +++ b/hubspot/src/main/kotlin/org/boomevents/hubspot/domain/associations/AssociationClient.kt @@ -4,7 +4,7 @@ import org.boomevents.hubspot.model.http.Requester import org.boomevents.hubspot.Client import org.boomevents.hubspot.ClientRequestCatalog import org.boomevents.hubspot.domain.associations.exceptions.AssociationException -import org.boomevents.hubspot.domain.deals.exceptions.AssociationNotFoundException +import org.boomevents.hubspot.domain.associations.exceptions.AssociationNotFoundException.Companion.fromJson import org.boomevents.hubspot.model.http.RequestMethod import org.boomevents.hubspot.model.http.exceptions.HttpRequestException import org.boomevents.hubspot.model.mapper.Mapper @@ -38,7 +38,7 @@ class AssociationClient(private val hubSpotClient: Client) { return Mapper.mapToObject(response.body) } else { when (response.status) { - 404 -> throw AssociationNotFoundException(request.fromObjectId) + 404 -> throw fromJson(response.body) else -> throw HttpRequestException(response.status, response.statusText) } } diff --git a/hubspot/src/main/kotlin/org/boomevents/hubspot/domain/associations/exceptions/AssociationNotFoundException.kt b/hubspot/src/main/kotlin/org/boomevents/hubspot/domain/associations/exceptions/AssociationNotFoundException.kt index 59b779f..2a92a41 100644 --- a/hubspot/src/main/kotlin/org/boomevents/hubspot/domain/associations/exceptions/AssociationNotFoundException.kt +++ b/hubspot/src/main/kotlin/org/boomevents/hubspot/domain/associations/exceptions/AssociationNotFoundException.kt @@ -1,20 +1,16 @@ -package org.boomevents.hubspot.domain.deals.exceptions +package org.boomevents.hubspot.domain.associations.exceptions -import org.boomevents.hubspot.domain.associations.exceptions.AssociationException +import kong.unirest.JsonNode import org.boomevents.hubspot.model.mapper.Mapper -import java.math.BigInteger data class AssociationErrorDetails( val objectType: String, val objectId: String ) -class AssociationNotFoundException( - val objectType: String, - val objectId: String -) : AssociationException("Association error: $objectType with ID $objectId was not found in Hubspot.") { +class AssociationNotFoundException(objectType: String, objectId: String) : AssociationException("Association error: $objectType with ID $objectId was not found in Hubspot.") { companion object { - fun fromJson(json: String): AssociationNotFoundException { + fun fromJson(json: JsonNode): AssociationNotFoundException { val errorDetails = Mapper.mapToObject(json) return AssociationNotFoundException(errorDetails.objectType, errorDetails.objectId) }