How can i respond with custom error in Akka gRPC

315 Views Asked by At

How does one send an error while using Akka-gRPC. I'm aware of responseObserver.Error when using native gRPC interfaces but can't find the best way to do it in Akka-gRPC.

I've tried doing this, however i'm not certain if this is a good approach and besides it doesn't provide benefits of using the google. advance error model

override fun createUser(req: CreateUserRequest?): CompletionStage<User>{
    requireNotNull(req)

    val validations = validator.validate(req.user)

    if (validations.isNotEmpty()) return CompletableFuture.failedStage(GrpcServiceException())

    val user = User.newBuilder().build()
    return CompletableFuture.completedFuture(user)
}
1

There are 1 best solutions below

1
Arnout Engelen On

You can use the GrpcServiceException for this: you can either fail the CompletionStage with it, or throw it from the createUser body.