You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/02/08 18:40:07 UTC

[isis-app-simpleapp] branch jpa updated: CustomController: don't fail on empty result

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch jpa
in repository https://gitbox.apache.org/repos/asf/isis-app-simpleapp.git


The following commit(s) were added to refs/heads/jpa by this push:
     new ca5e6ac  CustomController: don't fail on empty result
ca5e6ac is described below

commit ca5e6ac70792b821f99469401200de6936cdddaf
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Feb 8 19:39:55 2021 +0100

    CustomController: don't fail on empty result
---
 .../main/java/domainapp/webapp/custom/restapi/CustomController.java  | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/webapp/src/main/java/domainapp/webapp/custom/restapi/CustomController.java b/webapp/src/main/java/domainapp/webapp/custom/restapi/CustomController.java
index 4e0ec1c..887fa9f 100644
--- a/webapp/src/main/java/domainapp/webapp/custom/restapi/CustomController.java
+++ b/webapp/src/main/java/domainapp/webapp/custom/restapi/CustomController.java
@@ -1,5 +1,6 @@
 package domainapp.webapp.custom.restapi;
 
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Callable;
 
@@ -28,7 +29,9 @@ class CustomController {
 
   @GetMapping("/custom/simpleObjects")
   List<SimpleObject> all() {
-    return callAuthenticated(newAuthentication(), () -> repository.listAll()).orElseFail();
+    return callAuthenticated(newAuthentication(), () -> repository.listAll())
+            .optionalElseFail() // re-throws exception that has occurred, if any
+            .orElse(Collections.emptyList()); // handles null case, if required
   }
 
   private SimpleAuthentication newAuthentication() {