Skip to content

Commit

Permalink
SDK-2352: Add share error reason to example module
Browse files Browse the repository at this point in the history
  • Loading branch information
irotech committed Oct 30, 2023
1 parent 56348ea commit e5a5b32
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,32 @@ public String identityShare(Model model) {
public String receipt(@RequestParam("receiptId") String receiptId, Model model) {
Receipt receipt = execute(() -> client.fetchShareReceipt(receiptId), model);

if (receipt == null || receipt.getError().isPresent()) {
model.addAttribute("error", receipt.getError().get());
return "error";
}

Receipt.ApplicationContent applicationContent = receipt.getApplicationContent();
return Optional.ofNullable(receipt)
.map(r ->
receipt.getError()
.map(error -> {
model.addAttribute("error", error);
receipt.getErrorReason().ifPresent(reason ->
model.addAttribute("errorReason", reason)
);
return "error";
})
.orElseGet(() -> setProfile(receipt, model))
)
.orElse("error");
}

Optional.ofNullable(applicationContent.getProfile())
private String setProfile(Receipt receipt, Model model) {
Optional.ofNullable(receipt.getApplicationContent().getProfile())
.map(ApplicationProfile::getApplicationLogo)
.map(attr -> model.addAttribute("appLogo", attr.getValue().getBase64Content()));

receipt.getProfile().map(HumanProfile::getSelfie)
Optional<HumanProfile> profile = receipt.getProfile();
profile.map(HumanProfile::getSelfie)
.map(attr -> model.addAttribute("base64Selfie", attr.getValue().getBase64Content()));
receipt.getProfile().map(HumanProfile::getFullName)
profile.map(HumanProfile::getFullName)
.map(attr -> model.addAttribute("fullName", attr.getValue()));
receipt.getProfile().map(HumanProfile::getAttributes)
profile.map(HumanProfile::getAttributes)
.map(attr -> model.addAttribute("displayAttributes", mapAttributes(attr)));

return "profile";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public IdentitySessionController(DigitalIdentityClient client) {
public String identityShareSession() {
ShareSession session = client.createShareSession(
// forMinimalShare()
forDynamicScenarioShare()
// forIdentityProfileShare()
// forDynamicScenarioShare()
forIdentityProfileShare()
// forLocationExtensionShare()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@
<div class="box">
<h2><a href="/v2/digital-identity-share">Home</a></h2>
<h3>Oops, something went wrong.</h3>
<h3>Error: <span th:text="${error}"/></h3>
<h3>Error:</h3>
<span th:text="${error}"/>
<div th:if="${errorReason}">
<h3>Reason:</h3>
<pre id="error-reason-json" style="white-space: pre-wrap;"></pre>
</div>
</div>
</section>
</main>
</body>

<script th:inline="javascript">
document.getElementById("error-reason-json").textContent = JSON.stringify(/*[(${errorReason})]*/ '', null, 2);
</script>

</html>

0 comments on commit e5a5b32

Please sign in to comment.