Skip to content

Commit f749385

Browse files
authored
Merge pull request #343 from getyoti/SDK-2165
SDK-2165: Add ErrorDetails getter to ActivityFailureException
2 parents 05ca499 + bcdc264 commit f749385

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
package com.yoti.api.client;
22

3+
import java.util.Optional;
4+
5+
import com.yoti.api.client.spi.remote.call.ErrorDetails;
6+
import com.yoti.api.client.spi.remote.call.ProfileResponse;
7+
38
/**
49
* Signals activity failure -- ie. there was a problem during sharing.
510
*/
611
public class ActivityFailureException extends ProfileException {
712

813
private static final long serialVersionUID = 4496989849870743641L;
914

10-
public ActivityFailureException(String message) {
11-
super(message);
15+
private static final String ERROR_MSG = "Sharing activity unsuccessful for %s%s";
16+
17+
private final ErrorDetails errorDetails;
18+
19+
public ActivityFailureException(ProfileResponse profile) {
20+
super(
21+
String.format(
22+
ERROR_MSG,
23+
profile.getReceipt().getDisplayReceiptId(),
24+
Optional.ofNullable(profile.getError()).map(e -> String.format(" - %s", e)).orElse(""))
25+
);
26+
errorDetails = profile.getError();
27+
}
28+
29+
public ErrorDetails errorDetails() {
30+
return errorDetails;
1231
}
1332

1433
}

yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/ReceiptFetcher.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ private void validateReceipt(ProfileResponse profile, String connectToken) throw
5858
.orElseThrow(() -> new ProfileException("No profile for '" + connectToken + "' was found"));
5959

6060
if (!receipt.hasOutcome(Receipt.Outcome.SUCCESS)) {
61-
throw new ActivityFailureException(
62-
String.format("Sharing activity unsuccessful for %s%s",
63-
receipt.getDisplayReceiptId(),
64-
Optional.ofNullable(profile.getError()).map(e -> String.format(" - %s", e)).orElse("")
65-
)
66-
);
61+
throw new ActivityFailureException(profile);
6762
}
6863
}
6964

yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/ErrorDetails.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.yoti.api.client.spi.remote.call;
22

3+
import java.io.Serializable;
34
import java.util.Objects;
45

56
import com.fasterxml.jackson.annotation.JsonProperty;
67
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
78

89
@JsonDeserialize(builder = ErrorDetails.Builder.class)
9-
public final class ErrorDetails {
10+
public final class ErrorDetails implements Serializable {
11+
12+
private static final long serialVersionUID = -6429196723990930305L;
1013

1114
private final String code;
1215
private final String description;

yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/ReceiptFetcherTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,18 @@ public void shouldFailForFailureReceiptWithErrorCode() throws Exception {
154154
try {
155155
testObj.fetch(encryptedToken, keyPair, APP_ID);
156156
} catch (ActivityFailureException ex) {
157-
assertThat(ex.getMessage(), containsString(ENCODED_RECEIPT_STRING));
158-
assertThat(ex.getMessage(), containsString(errorCode));
159-
assertThat(ex.getMessage(), containsString(errorDescription));
157+
String exMsg = ex.getMessage();
158+
assertThat(exMsg, containsString(ENCODED_RECEIPT_STRING));
159+
assertThat(exMsg, containsString(errorCode));
160+
assertThat(exMsg, containsString(errorDescription));
161+
162+
ErrorDetails exError = ex.errorDetails();
163+
assertThat(exError.getCode(), is(equalTo(errorCode)));
164+
assertThat(exError.getDescription(), is(equalTo(errorDescription)));
165+
160166
return;
161167
}
168+
162169
fail("Expected an Exception");
163170
}
164171

0 commit comments

Comments
 (0)