diff options
author | Arpit Singh <as00745003@techmahindra.com> | 2024-07-09 17:20:51 +0530 |
---|---|---|
committer | Arpit Singh <as00745003@techmahindra.com> | 2024-07-24 16:54:38 +0530 |
commit | d9e391c4fc21f964ee16c7c289d8ced566bec794 (patch) | |
tree | f51879949912bb31b5b6fc4a6da1901c67581e86 /cps-service | |
parent | 5cba1b8333b4b2f2d97160f0ee210dde9f25aee1 (diff) |
Update response message for data validation failure
- Make the response message more informative and cleaner in case of data
validation failure.
- Updated message body will not contain the entire jsonData as part of
response sent back to the user
Issue-ID: CPS-2306
Change-Id: I28aab1450779af98ccdd11701e78bdfcdbc18cf0
Signed-off-by: Arpit Singh <as00745003@techmahindra.com>
Diffstat (limited to 'cps-service')
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/utils/YangParserHelper.java | 10 | ||||
-rw-r--r-- | cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy | 4 |
2 files changed, 5 insertions, 9 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/utils/YangParserHelper.java b/cps-service/src/main/java/org/onap/cps/utils/YangParserHelper.java index 5cadd29368..597164598a 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/YangParserHelper.java +++ b/cps-service/src/main/java/org/onap/cps/utils/YangParserHelper.java @@ -120,13 +120,9 @@ public class YangParserHelper { try (jsonParserStream) { jsonParserStream.parse(jsonReader); - } catch (final IOException | JsonSyntaxException exception) { + } catch (final IOException | JsonSyntaxException | IllegalStateException | IllegalArgumentException exception) { throw new DataValidationException( - "Failed to parse json data: " + jsonData, exception.getMessage(), exception); - } catch (final IllegalStateException | IllegalArgumentException exception) { - throw new DataValidationException( - "Failed to parse json data. Unsupported xpath or json data:" + jsonData, exception - .getMessage(), exception); + "Data Validation Failed", "Failed to parse json data. " + exception.getMessage(), exception); } return dataContainerNodeBuilder.build(); } @@ -168,7 +164,7 @@ public class YangParserHelper { } catch (final XMLStreamException | URISyntaxException | IOException | SAXException | NullPointerException | ParserConfigurationException | TransformerException exception) { throw new DataValidationException( - "Failed to parse xml data: " + xmlData, exception.getMessage(), exception); + "Data Validation Failed", "Failed to parse xml data: " + exception.getMessage(), exception); } final DataContainerChild dataContainerChild = (DataContainerChild) getFirstChildXmlRoot(normalizedNodeResult.getResult()); diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy index 2e38d797d9..0d3c5aa834 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy @@ -132,8 +132,8 @@ class CpsDataServiceImplSpec extends Specification { where: 'given parameters' scenario | invalidData | contentType || expectedMessage 'no data nodes' | '{}' | ContentType.JSON || 'No data nodes' - 'invalid json' | '{invalid json' | ContentType.JSON || 'Failed to parse json data' - 'invalid xml' | '<invalid xml' | ContentType.XML || 'Failed to parse xml data' + 'invalid json' | '{invalid json' | ContentType.JSON || 'Data Validation Failed' + 'invalid xml' | '<invalid xml' | ContentType.XML || 'Data Validation Failed' } def 'Saving list element data fragment under Root node.'() { |