From c4fc9d9496ba382eb371a65860caf2cd49261a06 Mon Sep 17 00:00:00 2001 From: Zach Smith Date: Tue, 31 Oct 2017 09:09:13 -0700 Subject: Change transformWith to recoverWith --- .../scala/xyz/driver/core/rest/HttpRestServiceTransport.scala | 10 +++++----- .../scala/xyz/driver/core/rest/errors/serviceException.scala | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/main/scala/xyz/driver/core') diff --git a/src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala b/src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala index 2bec4c3..376b154 100644 --- a/src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala +++ b/src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala @@ -58,11 +58,11 @@ class HttpRestServiceTransport(applicationName: Name[App], log.warn(s"Failed to receive response from ${request.method} ${request.uri} in $responseLatency ms", t) }(executionContext) - response.transformWith { - case Success(r) => Future.successful(r) - case Failure(_: TcpIdleTimeoutException) => - Future.failed(ExternalServiceTimeoutException()) - case Failure(t: Throwable) => Future.failed(t) + response.recoverWith { + case _: TcpIdleTimeoutException => + val serviceCalled = s"${requestStub.method} ${requestStub.uri}" + Future.failed(ExternalServiceTimeoutException(serviceCalled)) + case t: Throwable => Future.failed(t) } } diff --git a/src/main/scala/xyz/driver/core/rest/errors/serviceException.scala b/src/main/scala/xyz/driver/core/rest/errors/serviceException.scala index 82a1838..ca1f759 100644 --- a/src/main/scala/xyz/driver/core/rest/errors/serviceException.scala +++ b/src/main/scala/xyz/driver/core/rest/errors/serviceException.scala @@ -16,8 +16,8 @@ final case class ExternalServiceException(serviceName: String, serviceMessage: S override def message = s"Error while calling another service: $serviceMessage" } -final case class ExternalServiceTimeoutException( - override val message: String = "Another service took too long to respond") - extends ServiceException +final case class ExternalServiceTimeoutException(serviceName: String) extends ServiceException { + override def message = s"$serviceName took too long to respond" +} final case class DatabaseException(override val message: String = "Database access error") extends ServiceException -- cgit v1.2.3