Skip to content

Commit

Permalink
Merge pull request #3724 from Coduz/fix-jobEngineClientResponseHandli…
Browse files Browse the repository at this point in the history
…ngNPE

Added NPE checking on JobEngineClient response error handling
  • Loading branch information
Coduz authored Feb 23, 2023
2 parents 330ff5d + 374d37b commit 77e6b82
Showing 1 changed file with 10 additions and 1 deletion.
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);
}

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

0 comments on commit 77e6b82

Please sign in to comment.