use of de.rwth.idsg.steve.ocpp.ws.data.ErrorCode in project steve by RWTH-i5-IDSG.
the class Deserializer method handleError.
/**
* Do NOT catch and handle exceptions for incoming RESPONSEs. Let the processing fail.
* There is no mechanism in OCPP to report back such erroneous messages.
*/
private void handleError(CommunicationContext context, String messageId, JsonParser parser) {
FutureResponseContext responseContext = futureResponseContextStore.get(context.getSession(), messageId);
if (responseContext == null) {
throw new SteveException("An error message was received as response to a not-sent call. The message was: %s", context.getIncomingString());
}
ErrorCode code;
String desc;
String details = null;
try {
parser.nextToken();
code = ErrorCode.fromValue(parser.getText());
parser.nextToken();
desc = parser.getText();
// ErrorDescription - Should be filled in if possible, otherwise a clear empty string "".
if ("".equals(desc)) {
desc = null;
}
// From spec:
// ErrorDetails - This JSON object describes error details in an undefined way.
// If there are no error details you should fill in an empty object {}, missing or null is not allowed
parser.nextToken();
TreeNode detailsNode = parser.readValueAsTree();
if (detailsNode != null && detailsNode.size() != 0) {
details = mapper.writeValueAsString(detailsNode);
}
} catch (IOException e) {
throw new SteveException("Deserialization of incoming error message failed", e);
}
OcppJsonError error = new OcppJsonError();
error.setMessageId(messageId);
error.setErrorCode(code);
error.setErrorDescription(desc);
error.setErrorDetails(details);
context.setIncomingMessage(error);
context.createErrorHandler(responseContext.getTask());
}
Aggregations