diff --git a/agrirouter-api-java-api/src/main/java/com/dke/data/agrirouter/api/exception/OnboardingException.java b/agrirouter-api-java-api/src/main/java/com/dke/data/agrirouter/api/exception/OnboardingException.java index c879b8b4..13e868d7 100644 --- a/agrirouter-api-java-api/src/main/java/com/dke/data/agrirouter/api/exception/OnboardingException.java +++ b/agrirouter-api-java-api/src/main/java/com/dke/data/agrirouter/api/exception/OnboardingException.java @@ -23,4 +23,5 @@ public String getMessage() { onboardingError.getError().getCode(), onboardingError.getError().message) : "There was an error during the onboarding process."; } + } diff --git a/agrirouter-api-java-api/src/main/java/com/dke/data/agrirouter/api/exception/RevokingException.java b/agrirouter-api-java-api/src/main/java/com/dke/data/agrirouter/api/exception/RevokingException.java index c086c3ac..80125363 100644 --- a/agrirouter-api-java-api/src/main/java/com/dke/data/agrirouter/api/exception/RevokingException.java +++ b/agrirouter-api-java-api/src/main/java/com/dke/data/agrirouter/api/exception/RevokingException.java @@ -1,9 +1,27 @@ package com.dke.data.agrirouter.api.exception; +import com.dke.data.agrirouter.api.dto.revoke.RevokingError; + +import java.util.Optional; + public class RevokingException extends RuntimeException { - private final String lastError; + private final RevokingError revokingError; + + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") + public RevokingException(Optional lastError) { + this.revokingError = lastError.orElse(null); + } + + public RevokingError getRevokingError() { + return revokingError; + } - public RevokingException(String lastError) { - this.lastError = lastError; - } + @Override + public String getMessage() { + return null != revokingError + ? String.format( + "There was an error '%s' during the revoking, details were '%s'", + revokingError.getError().getCode(), revokingError.getError().message) + : "There was an error during the revoking process."; + } } diff --git a/agrirouter-api-java-impl/src/main/java/com/dke/data/agrirouter/impl/revoke/RevokingServiceImpl.java b/agrirouter-api-java-impl/src/main/java/com/dke/data/agrirouter/impl/revoke/RevokingServiceImpl.java index 5efa40d4..f78f9d27 100644 --- a/agrirouter-api-java-impl/src/main/java/com/dke/data/agrirouter/impl/revoke/RevokingServiceImpl.java +++ b/agrirouter-api-java-impl/src/main/java/com/dke/data/agrirouter/impl/revoke/RevokingServiceImpl.java @@ -48,8 +48,7 @@ public RevokeResponse revoke(RevokeParameters revokeParameters) { if (result.getKey() == RevokeResponse.SUCCESS.getKey()) { return result; } else { - String lastError = response.readEntity(String.class); - throw new RevokingException(lastError); + throw new RevokingException(getLastRevokingError(response.readEntity(String.class))); } } finally { if (response != null) {