[reactives3client] handle key not found
This commit is contained in:
parent
7af4004c75
commit
4e2729ae26
1 changed files with 9 additions and 5 deletions
|
@ -1,8 +1,9 @@
|
||||||
package net.kemitix.s3thorp
|
package net.kemitix.s3thorp
|
||||||
|
|
||||||
|
import cats.effect.IO
|
||||||
import com.github.j5ik2o.reactive.aws.s3.S3AsyncClient
|
import com.github.j5ik2o.reactive.aws.s3.S3AsyncClient
|
||||||
import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient
|
import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient
|
||||||
import software.amazon.awssdk.services.s3.model.HeadObjectRequest
|
import software.amazon.awssdk.services.s3.model.{HeadObjectRequest, NoSuchKeyException}
|
||||||
import software.amazon.awssdk.services.s3.{S3AsyncClient => JavaS3AsyncClient}
|
import software.amazon.awssdk.services.s3.{S3AsyncClient => JavaS3AsyncClient}
|
||||||
|
|
||||||
class ReactiveS3Client extends S3Client {
|
class ReactiveS3Client extends S3Client {
|
||||||
|
@ -14,9 +15,12 @@ class ReactiveS3Client extends S3Client {
|
||||||
.bucket(bucket)
|
.bucket(bucket)
|
||||||
.key(key)
|
.key(key)
|
||||||
.build()
|
.build()
|
||||||
for {
|
try {
|
||||||
response <- s3Client.headObject(request)
|
for {
|
||||||
// TODO catch 404 error when key doesn't exist
|
response <- s3Client.headObject(request)
|
||||||
} yield Some((response.eTag(), response.lastModified()))
|
} yield Some((response.eTag(), response.lastModified()))
|
||||||
|
} catch {
|
||||||
|
case _: NoSuchKeyException => IO(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue