Skip to content

Commit c133b8c

Browse files
authored
Merge pull request dropbox#135 from cakoose/cert-path
[IDEA] On CertPathValidationException, include cert path in exception message.
2 parents 281035b + c7232dd commit c133b8c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/main/java/com/dropbox/core/NetworkIOException.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.dropbox.core;
22

3+
import javax.net.ssl.SSLHandshakeException;
34
import java.io.IOException;
5+
import java.security.cert.CertPathValidatorException;
46

57
/**
68
* This gets thrown when there's an {@link IOException} when reading or writing to the
@@ -14,7 +16,24 @@ public class NetworkIOException extends DbxException {
1416
private static final long serialVersionUID = 0L;
1517

1618
public NetworkIOException(IOException cause) {
17-
super(cause.getMessage(), cause);
19+
super(computeMessage(cause), cause);
20+
}
21+
22+
private static String computeMessage(IOException ex) {
23+
String message = ex.getMessage();
24+
25+
// For CertPathValidationErrors, the CertPath is in the exception object but not
26+
// in the exception message. Pull it out into the message, because it would be
27+
// useful for debugging.
28+
if (ex instanceof SSLHandshakeException) {
29+
Throwable innerCause = ex.getCause();
30+
if (innerCause instanceof CertPathValidatorException) {
31+
CertPathValidatorException cpve = (CertPathValidatorException) innerCause;
32+
message += "[CERT PATH: " + cpve.getCertPath() + "]";
33+
}
34+
}
35+
36+
return message;
1837
}
1938

2039
@Override

0 commit comments

Comments
 (0)