From 3586cd0d71655454ba8f33bde891fb9ed4fac09f Mon Sep 17 00:00:00 2001 From: cmolinatnt Date: Wed, 8 Nov 2023 16:31:33 +0100 Subject: [PATCH] feat: adding proper exception for associations in the case the ids are wrong a non matching object is found --- .../AssociationNotFoundException.kt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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 f9da7e6..59b779f 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,9 +1,22 @@ package org.boomevents.hubspot.domain.deals.exceptions import org.boomevents.hubspot.domain.associations.exceptions.AssociationException +import org.boomevents.hubspot.model.mapper.Mapper import java.math.BigInteger +data class AssociationErrorDetails( + val objectType: String, + val objectId: String +) + class AssociationNotFoundException( - associationId: BigInteger, - override val message: String = "Association '$associationId' was not found." -) : AssociationException(message) + val objectType: String, + val objectId: String +) : AssociationException("Association error: $objectType with ID $objectId was not found in Hubspot.") { + companion object { + fun fromJson(json: String): AssociationNotFoundException { + val errorDetails = Mapper.mapToObject(json) + return AssociationNotFoundException(errorDetails.objectType, errorDetails.objectId) + } + } +}