Skip to content

Commit

Permalink
server: Add XSNWorkQueueDepthExceeded error
Browse files Browse the repository at this point in the history
Now, when the XSN RPC API returns the "Work Queue Depth Exceeded" error,
it will be mapped to the XSNWorkQueueDepthExceeded error.
  • Loading branch information
AlexITC committed Dec 15, 2018
1 parent 9c5dcbe commit e20d12c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions server/app/com/xsn/explorer/errors/xsnErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 7 additions & 1 deletion server/app/com/xsn/explorer/services/XSNService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class XSNServiceRPCImpl @Inject() (
.asOpt[JsValue]
.filter(_ != JsNull)

jsonErrorMaybe
val errorMaybe = jsonErrorMaybe
.flatMap { jsonError =>
// from error code if possible
(jsonError \ "code")
Expand All @@ -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](
Expand Down
13 changes: 13 additions & 0 deletions server/test/com/xsn/explorer/services/XSNServiceRPCImplSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e20d12c

Please sign in to comment.