Skip to content

Commit

Permalink
fix(associations): error exception receives wrong type
Browse files Browse the repository at this point in the history
  • Loading branch information
sitole committed Nov 9, 2023
1 parent 3586cd0 commit 8748a5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AssociationErrorDetails>(json)
return AssociationNotFoundException(errorDetails.objectType, errorDetails.objectId)
}
Expand Down

0 comments on commit 8748a5d

Please sign in to comment.