Skip to content

Commit

Permalink
Added NPE checking on JobEngineClient response error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Feb 23, 2023
1 parent 6966fb9 commit 785abb8
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

ExceptionInfo exceptionInfo = XmlUtil.unmarshalJson(responseText, ExceptionInfo.class, null);
switch (exceptionInfo.getKapuaErrorCode()) {
case "ENTITY_NOT_FOUND":
EntityNotFoundExceptionInfo entityNotFoundExceptionInfo = XmlUtil.unmarshalJson(responseText, EntityNotFoundExceptionInfo.class, null);
Expand Down

0 comments on commit 785abb8

Please sign in to comment.