Skip to content

Commit

Permalink
feat(s3stream): optimize error message for checking S3 availability
Browse files Browse the repository at this point in the history
Signed-off-by: SSpirits <admin@lv5.moe>
  • Loading branch information
ShadowySpirits committed Dec 28, 2023
1 parent f1308fb commit a52e47b
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
Expand Down Expand Up @@ -618,16 +619,21 @@ private void checkAvailable(S3Utils.S3Context s3Context) {
String exceptionMsg = String.format("Failed to write/read/delete object on S3. You are using s3Context: %s.", s3Context);

Throwable cause = e.getCause();
if (cause instanceof SdkClientException && cause.getMessage().startsWith("Unable to execute HTTP request")) {
exceptionMsg += "\nUnable to execute HTTP request. Please check your network connection and make sure you can access S3.";
if (cause instanceof SdkClientException) {
if (cause.getMessage().contains("UnknownHostException")) {
Throwable rootCause = ExceptionUtils.getRootCause(cause);
exceptionMsg += "\nUnable to resolve Host \"" + rootCause.getMessage() + "\". Please check your S3 endpoint.";
} else if (cause.getMessage().startsWith("Unable to execute HTTP request")) {
exceptionMsg += "\nUnable to execute HTTP request. Please check your network connection and make sure you can access S3.";
}
}

if (e instanceof TimeoutException || cause instanceof TimeoutException) {
exceptionMsg += "\nConnection timeout. Please check your network connection and make sure you can access S3.";
}

if (cause instanceof NoSuchBucketException) {
exceptionMsg += "\nBucket " + bucket + " not found. Please check your bucket name.";
exceptionMsg += "\nBucket \"" + bucket + "\" not found. Please check your bucket name.";
}

List<String> advices = s3Context.advices();
Expand Down

0 comments on commit a52e47b

Please # to comment.