mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-22 00:59:34 +01:00
improved error handling
This commit is contained in:
@@ -32,6 +32,7 @@ import java.security.InvalidAlgorithmParameterException;
|
|||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
import java.util.zip.InflaterInputStream;
|
import java.util.zip.InflaterInputStream;
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility to download files from the Internet.
|
* A utility to download files from the Internet.
|
||||||
@@ -175,7 +176,7 @@ public final class Downloader {
|
|||||||
}
|
}
|
||||||
LOGGER.debug("Download of {} complete", url.toString());
|
LOGGER.debug("Download of {} complete", url.toString());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
checkForSslExceptionn(ex);
|
checkForCommonExceptionTypes(ex);
|
||||||
final String msg = format("Error saving '%s' to file '%s'%nConnection Timeout: %d%nEncoding: %s%n",
|
final String msg = format("Error saving '%s' to file '%s'%nConnection Timeout: %d%nEncoding: %s%n",
|
||||||
url.toString(), outputPath.getAbsolutePath(), conn.getConnectTimeout(), encoding);
|
url.toString(), outputPath.getAbsolutePath(), conn.getConnectTimeout(), encoding);
|
||||||
throw new DownloadFailedException(msg, ex);
|
throw new DownloadFailedException(msg, ex);
|
||||||
@@ -261,10 +262,11 @@ public final class Downloader {
|
|||||||
} catch (URLConnectionFailureException ex) {
|
} catch (URLConnectionFailureException ex) {
|
||||||
throw new DownloadFailedException(format("Error creating URL Connection for HTTP %s request.", httpMethod), ex);
|
throw new DownloadFailedException(format("Error creating URL Connection for HTTP %s request.", httpMethod), ex);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
checkForSslExceptionn(ex);
|
checkForCommonExceptionTypes(ex);
|
||||||
LOGGER.error("IO Exception: " + ex.getMessage(), ex);
|
LOGGER.error("IO Exception: " + ex.getMessage());
|
||||||
|
LOGGER.debug("Exception details", ex);
|
||||||
if (ex.getCause() != null) {
|
if (ex.getCause() != null) {
|
||||||
LOGGER.error("IO Exception cause: " + ex.getCause().getMessage(), ex.getCause());
|
LOGGER.debug("IO Exception cause: " + ex.getCause().getMessage(), ex.getCause());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
//retry
|
//retry
|
||||||
@@ -292,15 +294,21 @@ public final class Downloader {
|
|||||||
/**
|
/**
|
||||||
* Analyzes the IOException, logs the appropriate information for debugging
|
* Analyzes the IOException, logs the appropriate information for debugging
|
||||||
* purposes, and then throws a DownloadFailedException that wraps the IO
|
* purposes, and then throws a DownloadFailedException that wraps the IO
|
||||||
* Exception.
|
* Exception for common IO Exceptions. This is to provide additional details
|
||||||
|
* to assist in resolution of the exception.
|
||||||
*
|
*
|
||||||
* @param ex the original exception
|
* @param ex the original exception
|
||||||
* @throws DownloadFailedException a wrapper exception that contains the
|
* @throws DownloadFailedException a wrapper exception that contains the
|
||||||
* original exception as the cause
|
* original exception as the cause
|
||||||
*/
|
*/
|
||||||
protected static void checkForSslExceptionn(IOException ex) throws DownloadFailedException {
|
protected static void checkForCommonExceptionTypes(IOException ex) throws DownloadFailedException {
|
||||||
Throwable cause = ex;
|
Throwable cause = ex;
|
||||||
while (cause != null) {
|
while (cause != null) {
|
||||||
|
if (cause instanceof java.net.UnknownHostException) {
|
||||||
|
final String msg = String.format("Unable to resolve domain '%s'", cause.getMessage());
|
||||||
|
LOGGER.error(msg);
|
||||||
|
throw new DownloadFailedException(msg);
|
||||||
|
}
|
||||||
if (cause instanceof InvalidAlgorithmParameterException) {
|
if (cause instanceof InvalidAlgorithmParameterException) {
|
||||||
final String keystore = System.getProperty("javax.net.ssl.keyStore");
|
final String keystore = System.getProperty("javax.net.ssl.keyStore");
|
||||||
final String version = System.getProperty("java.version");
|
final String version = System.getProperty("java.version");
|
||||||
@@ -315,6 +323,7 @@ public final class Downloader {
|
|||||||
cause = cause.getCause();
|
cause = cause.getCause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the HEAD or GET HTTP method. HEAD is the default.
|
* Returns the HEAD or GET HTTP method. HEAD is the default.
|
||||||
|
|||||||
Reference in New Issue
Block a user