fix(impact-analysis): 404 response is now properly caught.
@@ -28,6 +28,9 @@ import java.nio.file.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.synopsys.integration.blackduck.exception.BlackDuckApiException;
+import com.synopsys.integration.detect.exception.DetectUserFriendlyException;
+import com.synopsys.integration.detect.exitcode.ExitCodeType;
import com.synopsys.integration.detect.tool.impactanalysis.service.ImpactAnalysisService;
import com.synopsys.integration.detect.tool.impactanalysis.service.ImpactAnalysisUploadResult;
import com.synopsys.integration.detect.workflow.codelocation.CodeLocationNameManager;
@@ -58,19 +61,23 @@ public class VulnerabilityImpactAnalysisTool {
return outputReportPath;
}
- public ImpactAnalysisUploadResult uploadReport(Path reportPath, ImpactAnalysisService impactAnalysisService) throws IntegrationException {
+ public ImpactAnalysisUploadResult uploadReport(Path reportPath, ImpactAnalysisService impactAnalysisService) throws IntegrationException, DetectUserFriendlyException {
try {
logger.debug("Uploading report.");
ImpactAnalysisUploadResult impactAnalysisUploadResult = impactAnalysisService.uploadImpactAnalysisReport(reportPath);
logger.debug("Report upload completed.");
return impactAnalysisUploadResult;
- } catch (IntegrationRestException integrationRestException) {
-
+ } catch (BlackDuckApiException blackDuckApiException) {
+ IntegrationRestException integrationRestException = blackDuckApiException.getOriginalIntegrationRestException();
if (integrationRestException.getHttpStatusCode() == 404) {
- throw new IntegrationException("Report upload failed with 404. Your version of Black Duck may not support Vulnerability Impact Analysis.", integrationRestException);
+ throw new DetectUserFriendlyException("Report upload failed with 404. Your version of Black Duck may not support Vulnerability Impact Analysis.", integrationRestException, ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
} else {
- throw new IntegrationException(String.format("Report upload failed with status code %d: %s", integrationRestException.getHttpStatusCode(), integrationRestException.getHttpResponseContent()), integrationRestException);
+ throw new DetectUserFriendlyException(
+ String.format("Report upload failed with status code %d: %s", integrationRestException.getHttpStatusCode(), integrationRestException.getHttpResponseContent()),
+ integrationRestException,
+ ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR
+ );
}
} catch (IOException | IntegrationException exception) {
throw new IntegrationException(String.format("Report upload failed. %s", exception.getMessage()), exception);
