Repository: syncope
Updated Branches:
  refs/heads/2_0_X 29f9c5e39 -> 381625c7c
  refs/heads/master 3aba0a577 -> 86e593bda


Graceful handling of InvalidEntityExceptions for non-standard entities


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/381625c7
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/381625c7
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/381625c7

Branch: refs/heads/2_0_X
Commit: 381625c7c0bdc6dc2b6722aa870a458f9892f717
Parents: 29f9c5e
Author: Francesco Chicchiriccò <[email protected]>
Authored: Thu Sep 21 16:09:37 2017 +0200
Committer: Francesco Chicchiriccò <[email protected]>
Committed: Thu Sep 21 16:09:37 2017 +0200

----------------------------------------------------------------------
 .../core/rest/cxf/RestServiceExceptionMapper.java | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/381625c7/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java
----------------------------------------------------------------------
diff --git 
a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java
 
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java
index 718216e..2e77b37 100644
--- 
a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java
+++ 
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java
@@ -206,11 +206,19 @@ public class RestServiceExceptionMapper implements 
ExceptionMapper<Exception> {
         }
 
         if (iee != null) {
-            ClientExceptionType exType = 
iee.getEntityClassSimpleName().endsWith("Policy")
-                    ? ClientExceptionType.InvalidPolicy
-                    : 
iee.getEntityClassSimpleName().equals(PlainAttr.class.getSimpleName())
-                    ? ClientExceptionType.InvalidValues
-                    : ClientExceptionType.valueOf("Invalid" + 
iee.getEntityClassSimpleName());
+            ClientExceptionType exType;
+            if (iee.getEntityClassSimpleName().endsWith("Policy")) {
+                exType = ClientExceptionType.InvalidPolicy;
+            } else if 
(iee.getEntityClassSimpleName().equals(PlainAttr.class.getSimpleName())) {
+                exType = ClientExceptionType.InvalidValues;
+            } else {
+                try {
+                    exType = ClientExceptionType.valueOf("Invalid" + 
iee.getEntityClassSimpleName());
+                } catch (IllegalArgumentException e) {
+                    // ignore
+                    exType = ClientExceptionType.InvalidEntity;
+                }
+            }
 
             ResponseBuilder builder = 
Response.status(Response.Status.BAD_REQUEST);
             builder.header(RESTHeaders.ERROR_CODE, exType.name());

Reply via email to