Skip to content

Commit

Permalink
handle gRPC status error with no description (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zen Yui authored Nov 5, 2020
1 parent f34b222 commit 9e72707
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class AggregateCommandHandler(
def handleGrpcResponseFailure(status: Status): CommandHandlerResponse = {
val rpcStatus: RpcStatus = RpcStatus()
.withCode(status.getCode.value)
.withMessage(status.getDescription)
.withMessage(Option(status.getDescription).getOrElse(""))

val failureResponse = FailureResponse()
.withCustom(Any.pack(rpcStatus))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,17 @@ class AggregateCommandHandlerSpec extends CustomActorTestkit("application.conf")
actual.message shouldBe (status.getDescription())
}

"handle failed gRPC status with no description" in {
val status: Status = Status.ABORTED
val exception = new StatusRuntimeException(status)
val cmdhandler = new AggregateCommandHandler(null, testHandlerSetting)
val result: CommandHandlerResponse = cmdhandler.handleRemoteResponseFailure(exception)
result.getFailure.failureType.isCustom shouldBe (true)
val actual = result.getFailure.getCustom.unpack(RpcStatus)
actual.code shouldBe (status.getCode.value)
actual.message shouldBe ("")
}

"handle failed validations sent by command handler" in {
val badStatus: Status = Status.INVALID_ARGUMENT.withDescription("very invalid")
val exception: StatusRuntimeException = new StatusRuntimeException(badStatus)
Expand Down

0 comments on commit 9e72707

Please sign in to comment.