use of com.synopsys.integration.blackduck.exception.BlackDuckApiException in project hub-detect by blackducksoftware.
the class ExitCodeUtility method getExitCodeFromExceptionDetails.
public ExitCodeType getExitCodeFromExceptionDetails(final Exception e) {
final ExitCodeType exceptionExitCodeType;
if (e instanceof DetectUserFriendlyException) {
if (e.getCause() != null) {
logger.debug(e.getCause().getMessage(), e.getCause());
}
final DetectUserFriendlyException friendlyException = (DetectUserFriendlyException) e;
exceptionExitCodeType = friendlyException.getExitCodeType();
} else if (e instanceof BlackDuckApiException) {
BlackDuckApiException be = (BlackDuckApiException) e;
logger.error("A Black Duck Api exception was thrown.");
logger.error(be.getMessage());
logger.debug(be.getBlackDuckErrorCode());
logger.error(be.getOriginalIntegrationRestException().getMessage());
exceptionExitCodeType = ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR;
} else if (e instanceof IntegrationRestException) {
logger.error(BLACDUCK_ERROR_MESSAGE);
logger.debug(e.getMessage(), e);
exceptionExitCodeType = ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR;
} else if (e instanceof IntegrationException) {
logger.error(BLACDUCK_ERROR_MESSAGE);
logger.debug(e.getMessage(), e);
exceptionExitCodeType = ExitCodeType.FAILURE_GENERAL_ERROR;
} else {
logger.error("An unknown/unexpected error occurred");
if (e.getMessage() != null) {
logger.error(e.getMessage());
} else if (e instanceof NullPointerException) {
logger.error("Null Pointer Exception");
} else {
logger.error(e.getClass().getSimpleName());
}
if (e.getStackTrace().length >= 1) {
logger.error("Thrown at " + e.getStackTrace()[0].toString());
}
exceptionExitCodeType = ExitCodeType.FAILURE_UNKNOWN_ERROR;
}
if (e.getMessage() != null) {
logger.error(e.getMessage());
}
return exceptionExitCodeType;
}
Aggregations