From c7b422871efa60d7b7a03fb01c612c58bac42544 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Thu, 23 Oct 2014 10:40:37 -0700 Subject: [PATCH] Added some string constants to cover exception cases Change-Id: I102a7b136b6cc2d5c309e8c7984869aa51594e80 --- include/OCApi.h | 2 +- include/OCHeaderOption.h | 2 +- include/OCUtilities.h | 2 +- include/StringConstants.h | 7 ++++++- src/InProcServerWrapper.cpp | 5 ++--- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/OCApi.h b/include/OCApi.h index 30f9e4a..81a42bd 100644 --- a/include/OCApi.h +++ b/include/OCApi.h @@ -314,7 +314,7 @@ namespace OC } catch(boost::property_tree::json_parser::json_parser_error &e) { - throw OCException("JSON parse error"); + throw OCException(GENERAL_JSON_PARSE_FAILED); } for(auto& item: payload) diff --git a/include/OCHeaderOption.h b/include/OCHeaderOption.h index 73993f3..1d791c0 100644 --- a/include/OCHeaderOption.h +++ b/include/OCHeaderOption.h @@ -60,7 +60,7 @@ namespace OC { if(!(optionID >= MIN_HEADER_OPTIONID && optionID <= MAX_HEADER_OPTIONID)) { - throw OCException("Error:OptionID valid only from 2048 to 3000 inclusive"); + throw OCException(OC::Exception::OPTION_ID_RANGE_INVALID); } } diff --git a/include/OCUtilities.h b/include/OCUtilities.h index 35a6383..a736820 100644 --- a/include/OCUtilities.h +++ b/include/OCUtilities.h @@ -81,7 +81,7 @@ namespace OC { { if(nullptr == p) { - throw OCException("nullptr at nil_guard()", OC_STACK_INVALID_PARAM); + throw OCException(OC::Exception::NIL_GUARD_NULL, OC_STACK_INVALID_PARAM); } // Note that although parameters are being forwarded, std::bind() will make a single copy: diff --git a/include/StringConstants.h b/include/StringConstants.h index 24c985f..1892efd 100644 --- a/include/StringConstants.h +++ b/include/StringConstants.h @@ -58,7 +58,11 @@ namespace OC static const std::string INVALID_ARRAY = "Array type should have at least []"; static const std::string STR_NULL_RESPONSE = "Response is NULL"; static const std::string STR_PAYLOAD_OVERFLOW = "Payload overflow"; - + static const std::string NIL_GUARD_NULL = "nullptr at nil_guard()"; + static const std::string GENERAL_JSON_PARSE_FAILED = "JSON Parser Error"; + static const std::string RESOURCE_UNREG_FAILED = "Unregistering resource failed"; + static const std::string OPTION_ID_RANGE_INVALID = + "Error: OptionID valid only from 2048 to 3000 inclusive."; static const std::string NO_ERROR = "No Error"; static const std::string RESOURCE_CREATED = "Resource Created"; @@ -88,6 +92,7 @@ namespace OC static const std::string GENERAL_FAULT = "General Fault"; static const std::string MALFORMED_STACK_RESPONSE = "Response from OC_STACK is malformed"; static const std::string UNKNOWN_ERROR = "Unknown Error"; + } namespace Error diff --git a/src/InProcServerWrapper.cpp b/src/InProcServerWrapper.cpp index 43c9a77..f1f8214 100644 --- a/src/InProcServerWrapper.cpp +++ b/src/InProcServerWrapper.cpp @@ -89,7 +89,6 @@ void formResourceRequest(OCEntityHandlerFlag flag, if(OC_REST_GET == entityHandlerRequest->method) { - // TODO Why strings : "GET"?? pRequest->setRequestType(OC::PlatformCommands::GET); } else if(OC_REST_PUT == entityHandlerRequest->method) @@ -106,7 +105,7 @@ void formResourceRequest(OCEntityHandlerFlag flag, } else if(OC_REST_DELETE == entityHandlerRequest->method) { - pRequest->setRequestType("DELETE"); + pRequest->setRequestType(OC::PlatformCommands::DELETE); } } } @@ -423,7 +422,7 @@ namespace OC } else { - throw OCException("Unregistering resource failed", result); + throw OCException(OC::Exception::RESOURCE_UNREG_FAILED, result); } } else -- 2.7.4