This is an automated email from the ASF dual-hosted git repository. markusthoemmes pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push: new bfda2d1 Add detailed error/reason to status code. (#4403) bfda2d1 is described below commit bfda2d1715796751772d5ca78c1a7f32eb2063ec Author: Steffen Rost <sr...@de.ibm.com> AuthorDate: Thu Apr 4 10:53:17 2019 +0000 Add detailed error/reason to status code. (#4403) Co-authored-by: Sugandha Agrawal <sugandha.agrawa...@gmail.com> --- .../scala/org/apache/openwhisk/http/PoolingRestClient.scala | 13 ++++++++++--- .../org/apache/openwhisk/http/PoolingRestClientTests.scala | 7 +++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/common/scala/src/main/scala/org/apache/openwhisk/http/PoolingRestClient.scala b/common/scala/src/main/scala/org/apache/openwhisk/http/PoolingRestClient.scala index 3c8a2d3..bad6044 100644 --- a/common/scala/src/main/scala/org/apache/openwhisk/http/PoolingRestClient.scala +++ b/common/scala/src/main/scala/org/apache/openwhisk/http/PoolingRestClient.scala @@ -110,9 +110,16 @@ class PoolingRestClient( if (response.status.isSuccess) { Unmarshal(response.entity.withoutSizeLimit).to[T].map(Right.apply) } else { - // This is important, as it drains the entity stream. - // Otherwise the connection stays open and the pool dries up. - response.discardEntityBytes().future.map(_ => Left(response.status)) + Unmarshal(response.entity).to[String].flatMap { body => + val statusCode = response.status + val reason = + if (body.nonEmpty) s"${statusCode.reason} (details: $body)" else statusCode.reason + val customStatusCode = StatusCodes + .custom(intValue = statusCode.intValue, reason = reason, defaultMessage = statusCode.defaultMessage) + // This is important, as it drains the entity stream. + // Otherwise the connection stays open and the pool dries up. + response.discardEntityBytes().future.map(_ => Left(customStatusCode)) + } } } diff --git a/tests/src/test/scala/org/apache/openwhisk/http/PoolingRestClientTests.scala b/tests/src/test/scala/org/apache/openwhisk/http/PoolingRestClientTests.scala index ccb53d7..26dba87 100644 --- a/tests/src/test/scala/org/apache/openwhisk/http/PoolingRestClientTests.scala +++ b/tests/src/test/scala/org/apache/openwhisk/http/PoolingRestClientTests.scala @@ -138,12 +138,15 @@ class PoolingRestClientTests } it should "return a status code on request failure" in { - val httpResponse = HttpResponse(NotFound) + val body = "Limit is too large, must not exceed 268435456" + val httpResponse = HttpResponse(NotFound, entity = body) val httpRequest = HttpRequest(entity = HttpEntity(ContentTypes.`application/json`, JsObject.empty.compactPrint)) val poolingRestClient = new PoolingRestClient("https", "host", 443, 1, Some(testFlow(httpResponse, httpRequest))) val request = mkJsonRequest(GET, Uri./, JsObject.empty, List.empty) - await(poolingRestClient.requestJson[JsObject](request)) shouldBe Left(NotFound) + val reqResult = await(poolingRestClient.requestJson[JsObject](request)) + reqResult shouldBe Left(NotFound) + reqResult.left.get.reason shouldBe s"${NotFound.reason} (details: ${body})" } it should "throw an unsupported content-type exception when unexpected content-type is returned" in {