[reactives3client] handle NoSuchKeyException

This commit is contained in:
Paul Campbell 2019-05-10 07:57:53 +01:00
parent f991c2b7b0
commit c93bebb1e5

View file

@ -4,7 +4,7 @@ import cats.effect.IO
import net.kemitix.s3thorp.Main.putStrLn import net.kemitix.s3thorp.Main.putStrLn
import net.kemitix.s3thorp.Sync.{Bucket, LocalFile, RemoteKey} import net.kemitix.s3thorp.Sync.{Bucket, LocalFile, RemoteKey}
import software.amazon.awssdk.core.async.AsyncRequestBody import software.amazon.awssdk.core.async.AsyncRequestBody
import software.amazon.awssdk.services.s3.model.{HeadObjectRequest, NoSuchKeyException, PutObjectRequest} import software.amazon.awssdk.services.s3.model.{HeadObjectRequest, HeadObjectResponse, PutObjectRequest}
private class ReactiveS3Client private class ReactiveS3Client
extends S3Client extends S3Client
@ -15,15 +15,16 @@ private class ReactiveS3Client
.bucket(bucket) .bucket(bucket)
.key(remoteKey) .key(remoteKey)
.build() .build()
try { println(s"S3:HeadObject: $bucket : $remoteKey")
for { s3Client.headObject(request).attempt.map {
_ <- putStrLn(s"S3:HeadObject: $bucket : $remoteKey") case Right(response) => {
response <- s3Client.headObject(request) println(s" -- ${response.eTag()} : ${response.lastModified()}")
_ <- putStrLn(s" -- ${response.eTag()} : ${response.lastModified()}") Some((response.eTag(), response.lastModified()))
} yield Some((response.eTag(), response.lastModified())) }
} catch { case Left(_) => {
//FIXME: this isn't catching the exception println(" -- Not found in S3")
case _: NoSuchKeyException => IO(None) None
}
} }
} }