diff options
author | adamw <adam@warski.org> | 2017-08-31 14:32:01 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-08-31 14:32:01 +0200 |
commit | 71f6a1eeee412045cc08ce8894194573362cb8f0 (patch) | |
tree | c7618bb53f6e08c30df4e943f56d16fc1bfb80c1 /akka-http-handler/src/main | |
parent | 5bc89ddefab16dd814d0b716a72490451b697b32 (diff) | |
download | sttp-71f6a1eeee412045cc08ce8894194573362cb8f0.tar.gz sttp-71f6a1eeee412045cc08ce8894194573362cb8f0.tar.bz2 sttp-71f6a1eeee412045cc08ce8894194573362cb8f0.zip |
Response.body is now an Either[String, T], to handle cases when the status code isn't 2xx
Diffstat (limited to 'akka-http-handler/src/main')
-rw-r--r-- | akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala b/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala index 5691d3c..35f8f81 100644 --- a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala +++ b/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala @@ -41,8 +41,14 @@ class AkkaHttpHandler private (actorSystem: ActorSystem, .flatMap(Http().singleRequest(_)) .flatMap { hr => val code = hr.status.intValue() - bodyFromAkka(r.response, decodeAkkaResponse(hr)) - .map(Response(_, code, headersFromAkka(hr))) + + val body = if (codeIsSuccess(code)) { + bodyFromAkka(r.response, decodeAkkaResponse(hr)).map(Right(_)) + } else { + bodyFromAkka(asString, decodeAkkaResponse(hr)).map(Left(_)) + } + + body.map(Response(_, code, headersFromAkka(hr))) } } |