Skip to content

Commit f54254d

Browse files
committed
Merge pull request #21 from embulk/40x-config-error
40x HTTP errors happen due to config exception
2 parents 269e0af + dba7834 commit f54254d

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

embulk-input-s3/src/main/java/org/embulk/input/s3/AbstractS3FileInputPlugin.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.amazonaws.services.s3.model.GetObjectRequest;
2323
import com.amazonaws.services.s3.model.S3Object;
2424
import com.amazonaws.ClientConfiguration;
25+
import com.amazonaws.AmazonServiceException;
2526
import com.amazonaws.Protocol;
2627
import org.embulk.config.Config;
2728
import org.embulk.config.ConfigInject;
@@ -31,6 +32,7 @@
3132
import org.embulk.config.ConfigSource;
3233
import org.embulk.config.ConfigDiff;
3334
import org.embulk.config.TaskReport;
35+
import org.embulk.config.ConfigException;
3436
import org.embulk.spi.BufferAllocator;
3537
import org.embulk.spi.Exec;
3638
import org.embulk.spi.FileInputPlugin;
@@ -139,17 +141,29 @@ protected ClientConfiguration getClientConfiguration(PluginTask task)
139141

140142
private FileList listFiles(PluginTask task)
141143
{
142-
AmazonS3Client client = newS3Client(task);
143-
String bucketName = task.getBucket();
144+
try {
145+
AmazonS3Client client = newS3Client(task);
146+
String bucketName = task.getBucket();
144147

145-
if (task.getPathPrefix().equals("/")) {
146-
log.info("Listing files with prefix \"/\". This doesn't mean all files in a bucket. If you intend to read all files, use \"path_prefix: ''\" (empty string) instead.");
147-
}
148+
if (task.getPathPrefix().equals("/")) {
149+
log.info("Listing files with prefix \"/\". This doesn't mean all files in a bucket. If you intend to read all files, use \"path_prefix: ''\" (empty string) instead.");
150+
}
148151

149-
FileList.Builder builder = new FileList.Builder(task);
150-
listS3FilesByPrefix(builder, client, bucketName,
151-
task.getPathPrefix(), task.getLastPath());
152-
return builder.build();
152+
FileList.Builder builder = new FileList.Builder(task);
153+
listS3FilesByPrefix(builder, client, bucketName,
154+
task.getPathPrefix(), task.getLastPath());
155+
return builder.build();
156+
}
157+
catch (AmazonServiceException ex) {
158+
if (ex.getErrorType().equals(AmazonServiceException.ErrorType.Client)) {
159+
// HTTP 40x errors. auth error, bucket doesn't exist, etc. See AWS document for the full list:
160+
// http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
161+
if (ex.getStatusCode() != 400) { // 404 Bad Request is unexpected error
162+
throw new ConfigException(ex);
163+
}
164+
}
165+
throw ex;
166+
}
153167
}
154168

155169
/**

0 commit comments

Comments
 (0)