aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala')
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala12
1 files changed, 9 insertions, 3 deletions
diff --git a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala
index 548dd9b..ddc1293 100644
--- a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala
@@ -191,9 +191,15 @@ object HttpURLConnectionHandler extends SttpHandler[Id, Nothing] {
.filter(_._1 != null)
.flatMap { case (k, vv) => vv.asScala.map((k, _)) }
val contentEncoding = Option(c.getHeaderField(ContentEncodingHeader))
- Response(readResponseBody(wrapInput(contentEncoding, is), responseAs),
- c.getResponseCode,
- headers)
+ val code = c.getResponseCode
+ val wrappedIs = wrapInput(contentEncoding, is)
+ val body = if (codeIsSuccess(code)) {
+ Right(readResponseBody(wrappedIs, responseAs))
+ } else {
+ Left(readResponseBody(wrappedIs, asString))
+ }
+
+ Response(body, code, headers)
}
private def readResponseBody[T](is: InputStream,