Search in sources :

Example 1 with BlackDuckApiException

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;
}
Also used : ExitCodeType(com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckApiException(com.synopsys.integration.blackduck.exception.BlackDuckApiException)

Aggregations

DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 ExitCodeType (com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType)1 BlackDuckApiException (com.synopsys.integration.blackduck.exception.BlackDuckApiException)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)1