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