Browse Source

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.
prometheus-integration
Alexis Hernandez 6 years ago
parent
commit
e20d12cd54
  1. 8
      server/app/com/xsn/explorer/errors/xsnErrors.scala
  2. 8
      server/app/com/xsn/explorer/services/XSNService.scala
  3. 13
      server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala

8
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)
}
}

8
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](

13
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 {

Loading…
Cancel
Save