From 6b9f3064f1f658c4b929041cfaf304c175994e5e Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Thu, 2 Aug 2018 21:58:22 -0700 Subject: [PATCH] NOJIRA: Improved error message when post/putting payloads that contain unknown fields. --- .../services/common/document/DocumentUtils.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java index 1e74a1848..184d6d75c 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java @@ -1355,6 +1355,8 @@ public class DocumentUtils { result = loadSchema(schema, document, ctx); } catch (IllegalArgumentException iae) { throw iae; + } catch (DocumentException de) { + throw de; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -1519,9 +1521,16 @@ public class DocumentUtils { while (it.hasNext()) { org.dom4j.Element el = it.next(); String name = el.getName(); - Object value = getElementData(el, - ctype.getField(el.getName()).getType(), ctx); - map.put(name, value); + String elementText = el.getTextTrim(); + Field field = ctype.getField(el.getName()); + if (field != null) { + Object value = getElementData(el, field.getType(), ctx); // Break this up and check for null -i.e., does the field exist + map.put(name, value); + } else { + String msg = String.format("Unknown field '%s' in group '%s' with the value '%s'.", + name, ctype.getName(), elementText); + throw new DocumentException(msg); + } } result = map; } -- 2.47.3