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

1117/s3 dl mtd future should fail when request fails #1122

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions s3/src/main/scala/akka/stream/alpakka/s3/impl/S3Stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ private[alpakka] final class S3Stream(settings: S3Settings)(implicit system: Act
val s3Headers = S3Headers(sse.fold[Seq[HttpHeader]](Seq.empty) { _.headersFor(GetObject) })
val future = request(s3Location, rangeOption = range, versionId = versionId, s3Headers = s3Headers)
.map(response => response.withEntity(response.entity.withoutSizeLimit))
.flatMap(entityForSuccess)
val source = Source
.fromFuture(future.flatMap(entityForSuccess).map(_._1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see what's changing here. Aren't you just changing val future to include flatMap(entityForSuccess), rather than doing it in-line in the source declaration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jypma , this affects the error handling for the object metadata future as well, it will now fail on failed responses (i.e.404)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I see. So the effect of the change is not here, but in the line 103 which maps future which now has error handling because of the added .flatMap(entityForSuccess).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly

.fromFuture(future.map(_._1))
.map(_.dataBytes)
.flatMapConcat(identity)
val meta = future.map(resp computeMetaData(resp.headers, resp.entity))
val meta = future.map {
case (entity, headers) computeMetaData(headers, entity)
}
(source, meta)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,22 @@ class S3SourceSpec extends S3WireMockBase with S3ClientIntegrationSpec {

mock404s()

val result = s3Client
val (s3Strm, objMtdF) = s3Client
.download("nonexisting_bucket", "nonexisting_file.xml")
._1
val result = s3Strm
.map(_.utf8String)
.runWith(Sink.head)

whenReady(result.failed) { e =>
e shouldBe a[S3Exception]
e.asInstanceOf[S3Exception].code should equal("NoSuchKey")
}

whenReady(objMtdF.failed) { e =>
e.printStackTrace()
e shouldBe a[S3Exception]
e.asInstanceOf[S3Exception].code should equal("NoSuchKey")
}
}

it should "fail if download using server side encryption returns 'Invalid Request'" in {
Expand Down