diff options
author | zachdriver <zach@driver.xyz> | 2018-05-25 12:44:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-25 12:44:15 -0700 |
commit | d61ed25db4d71ac182f09ce7bc02439470f3a998 (patch) | |
tree | bdc0089e60ac7cf84e850e2024acd5ddbcdbaaa0 /src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala | |
parent | 57cd7aaf5a2154af698fddc39f4bff8fd3e4f6e7 (diff) | |
download | driver-core-d61ed25db4d71ac182f09ce7bc02439470f3a998.tar.gz driver-core-d61ed25db4d71ac182f09ce7bc02439470f3a998.tar.bz2 driver-core-d61ed25db4d71ac182f09ce7bc02439470f3a998.zip |
Add service exception json formatters and pass through exceptions in HttpRestServiceTransport (#168)v1.9.4
Diffstat (limited to 'src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala b/src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala index e54f722..788729a 100644 --- a/src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala +++ b/src/main/scala/xyz/driver/core/rest/HttpRestServiceTransport.scala @@ -75,8 +75,11 @@ class HttpRestServiceTransport( Future.successful(Unmarshal(HttpEntity.Empty: ResponseEntity)) } else if (response.status.isFailure()) { val serviceCalled = s"${requestStub.method} ${requestStub.uri}" - Unmarshal(response.entity).to[String] flatMap { error => - Future.failed(ExternalServiceException(serviceCalled, error)) + Unmarshal(response.entity).to[String] flatMap { errorString => + import spray.json._ + import xyz.driver.core.json._ + val serviceException = util.Try(serviceExceptionFormat.read(errorString.parseJson)).toOption + Future.failed(ExternalServiceException(serviceCalled, errorString, serviceException)) } } else { Future.successful(Unmarshal(response.entity)) |