aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/core/json.scala
diff options
context:
space:
mode:
authorzachdriver <zach@driver.xyz>2018-05-25 12:44:15 -0700
committerGitHub <noreply@github.com>2018-05-25 12:44:15 -0700
commitd61ed25db4d71ac182f09ce7bc02439470f3a998 (patch)
treebdc0089e60ac7cf84e850e2024acd5ddbcdbaaa0 /src/main/scala/xyz/driver/core/json.scala
parent57cd7aaf5a2154af698fddc39f4bff8fd3e4f6e7 (diff)
downloaddriver-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/json.scala')
-rw-r--r--src/main/scala/xyz/driver/core/json.scala19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/core/json.scala b/src/main/scala/xyz/driver/core/json.scala
index c1c5862..de1df31 100644
--- a/src/main/scala/xyz/driver/core/json.scala
+++ b/src/main/scala/xyz/driver/core/json.scala
@@ -16,6 +16,7 @@ import spray.json._
import xyz.driver.core.auth.AuthCredentials
import xyz.driver.core.date.{Date, DayOfWeek, Month}
import xyz.driver.core.domain.{Email, PhoneNumber}
+import xyz.driver.core.rest.errors._
import xyz.driver.core.time.{Time, TimeOfDay}
import scala.reflect.runtime.universe._
@@ -368,6 +369,24 @@ object json {
NonEmptyName[T](nonEmptyStringFormat.read(value))
}
+ implicit val serviceExceptionFormat: RootJsonFormat[ServiceException] =
+ GadtJsonFormat.create[ServiceException]("type") {
+ case _: InvalidInputException => "InvalidInputException"
+ case _: InvalidActionException => "InvalidActionException"
+ case _: ResourceNotFoundException => "ResourceNotFoundException"
+ case _: ExternalServiceException => "ExternalServiceException"
+ case _: ExternalServiceTimeoutException => "ExternalServiceTimeoutException"
+ case _: DatabaseException => "DatabaseException"
+ } {
+ case "InvalidInputException" => jsonFormat(InvalidInputException, "message")
+ case "InvalidActionException" => jsonFormat(InvalidActionException, "message")
+ case "ResourceNotFoundException" => jsonFormat(ResourceNotFoundException, "message")
+ case "ExternalServiceException" =>
+ jsonFormat(ExternalServiceException, "serviceName", "serviceMessage", "serviceException")
+ case "ExternalServiceTimeoutException" => jsonFormat(ExternalServiceTimeoutException, "message")
+ case "DatabaseException" => jsonFormat(DatabaseException, "message")
+ }
+
val jsValueToStringMarshaller: Marshaller[JsValue, String] =
Marshaller.strict[JsValue, String](value => Marshalling.Opaque[String](() => value.compactPrint))