diff options
author | Zach Smith <zach@driver.xyz> | 2017-10-31 09:09:13 -0700 |
---|---|---|
committer | Zach Smith <zach@driver.xyz> | 2017-10-31 09:19:04 -0700 |
commit | c4fc9d9496ba382eb371a65860caf2cd49261a06 (patch) | |
tree | 84e458c896a9aa2322c9a3c9600ac2a56e2dd433 /src/main/scala/xyz/driver/core/rest | |
parent | 5f3330ffd4df8d87b97d88789aced1b1b8f7410d (diff) | |
download | driver-core-c4fc9d9496ba382eb371a65860caf2cd49261a06.tar.gz driver-core-c4fc9d9496ba382eb371a65860caf2cd49261a06.tar.bz2 driver-core-c4fc9d9496ba382eb371a65860caf2cd49261a06.zip |
Change transformWith to recoverWith
Diffstat (limited to 'src/main/scala/xyz/driver/core/rest')
-rw-r--r-- | src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala | 10 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/core/rest/errors/serviceException.scala | 6 |
2 files changed, 8 insertions, 8 deletions
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 |