summaryrefslogtreecommitdiff
path: root/src/components/smart_objects/include/smart_objects/default_shema_item.h
diff options
context:
space:
mode:
authorJacob Keeler <jacob.keeler@livioradio.com>2017-05-04 12:18:40 -0400
committerJacob Keeler <jacob.keeler@livioradio.com>2017-05-04 12:18:40 -0400
commit884e897941a600c11b7fcfa3d8cf59ce15eb3571 (patch)
tree1d5b0d1abbdcdd7c2661a59b3c10b6110fbf53a3 /src/components/smart_objects/include/smart_objects/default_shema_item.h
parentdc9732721e1690159fb56e0b5f5e9d643c9a9d44 (diff)
downloadsdl_core-884e897941a600c11b7fcfa3d8cf59ce15eb3571.tar.gz
Invalid data responses now return useful error messages in `info` field
Diffstat (limited to 'src/components/smart_objects/include/smart_objects/default_shema_item.h')
-rw-r--r--src/components/smart_objects/include/smart_objects/default_shema_item.h20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/components/smart_objects/include/smart_objects/default_shema_item.h b/src/components/smart_objects/include/smart_objects/default_shema_item.h
index 857354a4e6..6bac513b16 100644
--- a/src/components/smart_objects/include/smart_objects/default_shema_item.h
+++ b/src/components/smart_objects/include/smart_objects/default_shema_item.h
@@ -54,7 +54,8 @@ class CDefaultSchemaItem : public ISchemaItem {
* @param Object Object to validate.
* @return NsSmartObjects::Errors::eType
**/
- Errors::eType validate(const SmartObject& Object) OVERRIDE;
+ Errors::eType validate(const SmartObject& Object,
+ std::string& errorMessage) OVERRIDE;
/**
* @brief Set default value to an object.
@@ -98,9 +99,20 @@ CDefaultSchemaItem<Type>::CDefaultSchemaItem(const ParameterType& DefaultValue)
: mDefaultValue(DefaultValue) {}
template <typename Type>
-Errors::eType CDefaultSchemaItem<Type>::validate(const SmartObject& Object) {
- return (getSmartType() == Object.getType()) ? Errors::OK
- : Errors::INVALID_VALUE;
+Errors::eType CDefaultSchemaItem<Type>::validate(const SmartObject& Object,
+ std::string& errorMessage) {
+ if (getSmartType() != Object.getType()) {
+ if (!Object.getKey().empty()) {
+ errorMessage.assign("Validation failed for \"" + Object.getKey() +
+ "\". ");
+ }
+ errorMessage += "Incorrect type, expected: " +
+ SmartObject::typeToString(getSmartType()) + ", got: " +
+ SmartObject::typeToString(Object.getType());
+ return Errors::INVALID_VALUE;
+ } else {
+ return Errors::OK;
+ }
}
template <typename Type>