Skip to content

Commit f85a0a6

Browse files
authored
Merge pull request #220 from c-jimenez/dev/add_log_in_invalid_response
[message] Add error log when response to call request doesn't match the JSON schema
2 parents f11481a + 159258e commit f85a0a6

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/messages/GenericMessageSender.h

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
2121

2222
#include "IRequestFifo.h"
2323
#include "IRpc.h"
24+
#include "Logger.h"
2425
#include "MessagesConverter.h"
2526
#include "MessagesValidator.h"
2627

@@ -152,15 +153,22 @@ class GenericMessageSender
152153
{
153154
// Validate response
154155
ocpp::json::JsonValidator* validator = m_messages_validator.getValidator(action, false);
155-
if (validator && validator->isValid(resp))
156+
if (validator)
156157
{
157-
// Convert response
158-
std::string error_code;
159-
std::string error_message;
160-
resp_converter->setAllocator(&rpc_frame.GetAllocator());
161-
if (resp_converter->fromJson(resp, response, error_code, error_message))
158+
if (validator->isValid(resp))
162159
{
163-
ret = CallResult::Ok;
160+
// Convert response
161+
std::string error_code;
162+
std::string error_message;
163+
resp_converter->setAllocator(&rpc_frame.GetAllocator());
164+
if (resp_converter->fromJson(resp, response, error_code, error_message))
165+
{
166+
ret = CallResult::Ok;
167+
}
168+
}
169+
else
170+
{
171+
LOG_ERROR << "[" << action << "] - Invalid response : " << validator->lastError();
164172
}
165173
}
166174
}
@@ -219,15 +227,22 @@ class GenericMessageSender
219227
{
220228
// Validate response
221229
ocpp::json::JsonValidator* validator = m_messages_validator.getValidator(action, false);
222-
if (validator && validator->isValid(resp))
230+
if (validator)
223231
{
224-
// Convert response
225-
std::string error_code;
226-
std::string error_message;
227-
resp_converter->setAllocator(&rpc_frame.GetAllocator());
228-
if (resp_converter->fromJson(resp, response, error_code, error_message))
232+
if (validator->isValid(resp))
233+
{
234+
// Convert response
235+
std::string error_code;
236+
std::string error_message;
237+
resp_converter->setAllocator(&rpc_frame.GetAllocator());
238+
if (resp_converter->fromJson(resp, response, error_code, error_message))
239+
{
240+
ret = CallResult::Ok;
241+
}
242+
}
243+
else
229244
{
230-
ret = CallResult::Ok;
245+
LOG_ERROR << "[" << action << "] - Invalid response : " << validator->lastError();
231246
}
232247
}
233248
}

0 commit comments

Comments
 (0)