From e20d12cd54f00546afb379977f993f44555b63d3 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Fri, 14 Dec 2018 23:13:22 -0700 Subject: [PATCH] server: Add XSNWorkQueueDepthExceeded error Now, when the XSN RPC API returns the "Work Queue Depth Exceeded" error, it will be mapped to the XSNWorkQueueDepthExceeded error. --- server/app/com/xsn/explorer/errors/xsnErrors.scala | 8 ++++++++ .../app/com/xsn/explorer/services/XSNService.scala | 8 +++++++- .../explorer/services/XSNServiceRPCImplSpec.scala | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/server/app/com/xsn/explorer/errors/xsnErrors.scala b/server/app/com/xsn/explorer/errors/xsnErrors.scala index ae2eb0f..d3c7e2b 100644 --- a/server/app/com/xsn/explorer/errors/xsnErrors.scala +++ b/server/app/com/xsn/explorer/errors/xsnErrors.scala @@ -24,3 +24,11 @@ case object XSNUnexpectedResponseError extends XSNServerError { List(error) } } + +case object XSNWorkQueueDepthExceeded extends XSNServerError { + override def toPublicErrorList(messagesApi: MessagesApi)(implicit lang: Lang): List[PublicError] = { + val message = messagesApi("xsn.server.unexpectedError") + val error = GenericPublicError(message) + List(error) + } +} diff --git a/server/app/com/xsn/explorer/services/XSNService.scala b/server/app/com/xsn/explorer/services/XSNService.scala index f832a0f..cabf7c3 100644 --- a/server/app/com/xsn/explorer/services/XSNService.scala +++ b/server/app/com/xsn/explorer/services/XSNService.scala @@ -402,7 +402,7 @@ class XSNServiceRPCImpl @Inject() ( .asOpt[JsValue] .filter(_ != JsNull) - jsonErrorMaybe + val errorMaybe = jsonErrorMaybe .flatMap { jsonError => // from error code if possible (jsonError \ "code") @@ -416,6 +416,12 @@ class XSNServiceRPCImpl @Inject() ( .map(XSNMessageError.apply) } } + + errorMaybe + .collect { + case XSNMessageError("Work queue depth exceeded") => XSNWorkQueueDepthExceeded + } + .orElse(errorMaybe) } private def getResult[A]( diff --git a/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala b/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala index 82b1019..bfb01b9 100644 --- a/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala +++ b/server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala @@ -163,6 +163,19 @@ class XSNServiceRPCImplSpec extends WordSpec with MustMatchers with ScalaFutures result mustEqual Bad(XSNUnexpectedResponseError).accumulating } } + + "handle work queue depth exceeded" in { + val txid = createTransactionId("0834641a7d30d8a2d2b451617599670445ee94ed7736e146c13be260c576c641") + + val responseBody = createRPCErrorResponse(-1, "Work queue depth exceeded") + val json = Json.parse(responseBody) + + mockRequest(request, response)(200, json) + + whenReady(service.getTransaction(txid)) { result => + result mustEqual Bad(XSNWorkQueueDepthExceeded).accumulating + } + } } "getRawTransaction" should {