Skip to content

Commit abe44ba

Browse files
authored
eval operation err code before creating conf (#290)
* change execution order getErr <> createConf * update changelog
1 parent ffbb6e4 commit abe44ba

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- Fix transaction freeze in offline mode ([#279](https://github.com/matth-x/MicroOcpp/pull/279), [#287](https://github.com/matth-x/MicroOcpp/pull/287))
3939
- Fix compilation error caused by `PRId32` ([#279](https://github.com/matth-x/MicroOcpp/pull/279))
4040
- Don't load FW-mngt. module when no handlers set
41+
- Avoid creating conf when operation fails ([#290](https://github.com/matth-x/MicroOcpp/pull/290))
4142

4243
## [1.0.3] - 2024-04-06
4344

src/MicroOcpp/Core/Request.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// matth-x/MicroOcpp
2-
// Copyright Matthias Akstaller 2019 - 2023
2+
// Copyright Matthias Akstaller 2019 - 2024
33
// MIT License
44

55
#include <MicroOcpp/Core/Request.h>
@@ -184,17 +184,17 @@ std::unique_ptr<DynamicJsonDocument> Request::createResponse(){
184184
* Create the OCPP message
185185
*/
186186
std::unique_ptr<DynamicJsonDocument> response = nullptr;
187-
std::unique_ptr<DynamicJsonDocument> payload = operation->createConf();
188-
std::unique_ptr<DynamicJsonDocument> errorDetails = nullptr;
189-
190-
bool operationFailure = operation->getErrorCode() != nullptr;
191187

192-
if (!operationFailure && !payload) {
193-
return nullptr; //confirmation message still pending
194-
}
188+
bool operationFailure = operation->getErrorCode() != nullptr;
195189

196190
if (!operationFailure) {
197191

192+
std::unique_ptr<DynamicJsonDocument> payload = operation->createConf();
193+
194+
if (!payload) {
195+
return nullptr; //confirmation message still pending
196+
}
197+
198198
/*
199199
* Create OCPP-J Remote Procedure Call header
200200
*/
@@ -213,7 +213,7 @@ std::unique_ptr<DynamicJsonDocument> Request::createResponse(){
213213

214214
const char *errorCode = operation->getErrorCode();
215215
const char *errorDescription = operation->getErrorDescription();
216-
errorDetails = std::unique_ptr<DynamicJsonDocument>(operation->getErrorDetails());
216+
std::unique_ptr<DynamicJsonDocument> errorDetails = std::unique_ptr<DynamicJsonDocument>(operation->getErrorDetails());
217217
if (!errorCode) { //catch corner case when payload is null but errorCode is not set too!
218218
errorCode = "GenericError";
219219
errorDescription = "Could not create payload (createConf() returns Null)";

0 commit comments

Comments
 (0)