From 374d37be14846033bcea0366bd781bae672a09c3 Mon Sep 17 00:00:00 2001 From: Alberto Codutti Date: Wed, 22 Feb 2023 15:28:50 +0100 Subject: [PATCH] Added NPE checking on JobEngineClient response error handling Signed-off-by: Alberto Codutti --- .../job/engine/client/JobEngineServiceClient.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/job-engine/client/src/main/java/org/eclipse/kapua/job/engine/client/JobEngineServiceClient.java b/job-engine/client/src/main/java/org/eclipse/kapua/job/engine/client/JobEngineServiceClient.java index 21bac788e7a..4b72c4a66d7 100644 --- a/job-engine/client/src/main/java/org/eclipse/kapua/job/engine/client/JobEngineServiceClient.java +++ b/job-engine/client/src/main/java/org/eclipse/kapua/job/engine/client/JobEngineServiceClient.java @@ -275,10 +275,19 @@ private String checkResponse(String method, String path, Response response) thro private KapuaException buildJobEngineExceptionFromResponse(String responseText) { try { if (StringUtils.isBlank(responseText)) { - throw new KapuaRuntimeException(KapuaErrorCodes.INTERNAL_ERROR, "Job Engine returned an error but no message was given"); + throw new KapuaRuntimeException(KapuaErrorCodes.INTERNAL_ERROR, "JobEngine returned an error but no message was given"); } ExceptionInfo exceptionInfo = XmlUtil.unmarshalJson(responseText, ExceptionInfo.class); + + if (exceptionInfo == null) { + throw new KapuaRuntimeException(KapuaErrorCodes.INTERNAL_ERROR, "Job Engine returned an not-empty response but it was not deserializable as an ExceptionInfo. Content returned: " + responseText); + } + + if (exceptionInfo.getKapuaErrorCode() == null) { + throw new KapuaRuntimeException(KapuaErrorCodes.INTERNAL_ERROR, "Job Engine returned an ExceptionInfo without a KapuaErrorCode. Content returned: " + responseText); + } + switch (exceptionInfo.getKapuaErrorCode()) { case "ENTITY_NOT_FOUND": EntityNotFoundExceptionInfo entityNotFoundExceptionInfo = XmlUtil.unmarshalJson(responseText, EntityNotFoundExceptionInfo.class);