Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 getObject exception cant return correct status code when object key not exist. #365

Closed
counter2015 opened this issue Nov 15, 2022 · 0 comments · Fixed by #371
Closed

Comments

@counter2015
Copy link

counter2015 commented Nov 15, 2022

verison: 0.4.2.1

import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.s3.S3Client
import software.amazon.awssdk.services.s3.model._
import zio._
import zio.s3.getObject
import zio.stream.ZStream

object Test1 extends ZIOAppDefault {

  override def run: ZIO[Any with ZIOAppArgs with Scope, Throwable, Unit] = {
    val bucketName = "cassandra-dev"
    val key = "not-exist-key"

    def awsGetObject() = {

      val region = Region.CN_NORTHWEST_1
      val client = S3Client.builder.region(region).build

      val request = GetObjectRequest
        .builder()
        .bucket(bucketName)
        .key(key)
        .build()

      try {
        client.getObject(request)
      } catch {
        case e: S3Exception =>
          println("aws sdk return code:" + e.statusCode())
      }
    }
    awsGetObject()

    getObject(bucketName, key).catchAll { e =>
      println("zio s3 return code:" + e.statusCode())
      ZStream.fromIterable(Array[Byte]())
    }.runDrain.provideLayer(layer.all)
  }

}

output:

aws sdk return code:404
zio s3 return code:0

It should return 404 rather than 0.

It seems that the builder not init correctly?

.flatMap(identity)
.flattenChunks
.mapError(e => S3Exception.builder().message(e.getMessage).cause(e).build())
.refineOrDie {
case e: S3Exception => e
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant