X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=vid-app-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fvid%2Fmso%2FMsoUtil.java;h=8de534a8ef50bffdf4326148d4d62613e9b932a1;hb=adef7f90d338e0e93e3a3d0a6f714f0270a9b7f1;hp=626816f7fa01ca2c30a77159ae7430b71073fb17;hpb=47cc63c50442005b3ac051d4c4e3037139b7f1e5;p=vid.git diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java index 626816f7f..8de534a8e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java @@ -21,15 +21,15 @@ package org.onap.vid.mso; +import static org.apache.commons.lang3.StringUtils.firstNonBlank; +import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; -import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import io.joshworks.restclient.http.HttpResponse; import java.io.IOException; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; -import org.onap.vid.exceptions.GenericUncheckedException; public class MsoUtil { @@ -76,22 +76,31 @@ public class MsoUtil { } public static String formatExceptionAdditionalInfo(int statusCode, String msoResponse) { - String errorMsg = "Http Code:" + statusCode; - if (!StringUtils.isEmpty(msoResponse)) { - String filteredJson; - try { - filteredJson = StringUtils.defaultIfEmpty( - JACKSON_OBJECT_MAPPER.readTree(msoResponse).path("serviceException").toString().replaceAll("[\\{\\}]","") , - msoResponse - ); - } catch (JsonParseException e) { - filteredJson = msoResponse; - } catch (IOException e) { - throw new GenericUncheckedException(e); - } + final String errorMsg = "Http Code:" + statusCode; + + if (isEmpty(msoResponse)) { + return errorMsg; + } + + try { + JsonNode jsonNode = JACKSON_OBJECT_MAPPER.readTree(msoResponse); - errorMsg = errorMsg + ", " + filteredJson; + return errorMsg + ", " + firstNonBlank( + removeBraces(jsonNode.get("serviceException")), + removeBraces(jsonNode.path("requestError").get("serviceException")), + msoResponse + ); + + } catch (Exception e) { + return errorMsg + ", " + msoResponse; } - return errorMsg; + } + + private static String removeBraces(JsonNode jsonNode) { + if (jsonNode == null || jsonNode.isMissingNode()) { + return null; + } + + return jsonNode.toString().replaceAll("[\\{\\}]", ""); } }