From b2c9019ce1faf6b124ca416d0bfb13d0d4080322 Mon Sep 17 00:00:00 2001 From: Pask Date: Thu, 15 Sep 2022 18:56:50 +0200 Subject: [PATCH 1/2] Add status text resolver --- core/src/main/scala/sttp/client3/Response.scala | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/src/main/scala/sttp/client3/Response.scala b/core/src/main/scala/sttp/client3/Response.scala index e896dfc2e0..c4f2205fd6 100644 --- a/core/src/main/scala/sttp/client3/Response.scala +++ b/core/src/main/scala/sttp/client3/Response.scala @@ -1,6 +1,6 @@ package sttp.client3 -import sttp.model.{Header, HeaderNames, Headers, Method, RequestMetadata, ResponseMetadata, StatusCode, Uri} +import sttp.model.{Header, HeaderNames, Headers, Method, RequestMetadata, ResponseMetadata, StatusCode, StatusText, Uri} import scala.collection.immutable.Seq @@ -45,22 +45,26 @@ object Response { * [[sttp.client3.testing.SttpBackendStub]] and partial matchers. */ def apply[T](body: T, code: StatusCode): Response[T] = - Response(body, code, "", Nil, Nil, ExampleGet) + Response(body, code, resolveStatusText(code), Nil, Nil, ExampleGet) /** Convenience method to create a Response instance, mainly useful in tests using * [[sttp.client3.testing.SttpBackendStub]] and partial matchers. */ def apply[T](body: T, code: StatusCode, statusText: String): Response[T] = - Response(body, code, statusText, Nil, Nil, ExampleGet) + Response(body, code, resolveStatusText(code, statusText), Nil, Nil, ExampleGet) /** Convenience method to create a Response instance, mainly useful in tests using * [[sttp.client3.testing.SttpBackendStub]] and partial matchers. */ def apply[T](body: T, code: StatusCode, statusText: String, headers: Seq[Header]): Response[T] = - Response(body, code, statusText, headers, Nil, ExampleGet) + Response(body, code, resolveStatusText(code, statusText), headers, Nil, ExampleGet) /** Convenience method to create a Response instance, mainly useful in tests using * [[sttp.client3.testing.SttpBackendStub]] and partial matchers. */ - def ok[T](body: T): Response[T] = apply(body, StatusCode.Ok, "OK") + def ok[T](body: T): Response[T] = apply(body, StatusCode.Ok) + + def resolveStatusText(statusCode: StatusCode, provided: String = ""): String = + if (provided.isEmpty) StatusText.default(statusCode).getOrElse(provided) + else provided } From f490e7062f78180d9d3d8a4f6c14929ac7895541 Mon Sep 17 00:00:00 2001 From: Pask Date: Thu, 15 Sep 2022 22:40:33 +0200 Subject: [PATCH 2/2] Added access modifier --- core/src/main/scala/sttp/client3/Response.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/scala/sttp/client3/Response.scala b/core/src/main/scala/sttp/client3/Response.scala index c4f2205fd6..39fb047842 100644 --- a/core/src/main/scala/sttp/client3/Response.scala +++ b/core/src/main/scala/sttp/client3/Response.scala @@ -64,7 +64,7 @@ object Response { */ def ok[T](body: T): Response[T] = apply(body, StatusCode.Ok) - def resolveStatusText(statusCode: StatusCode, provided: String = ""): String = + private def resolveStatusText(statusCode: StatusCode, provided: String = ""): String = if (provided.isEmpty) StatusText.default(statusCode).getOrElse(provided) else provided }