Skip to content

Commit

Permalink
1117/s3 dl mtd future should fail when request fails (akka#1122)
Browse files Browse the repository at this point in the history
* 1117: fix the issue by extracting errors before looking at the returned headers.
  • Loading branch information
eyalfa authored and sebastianharko committed Sep 5, 2018
1 parent d73c55b commit 7628870
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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))
.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

0 comments on commit 7628870

Please sign in to comment.