How to send custom error from my GRPC Load balancer

7/4/2019

I am working on my own custom GRPCLoadBalancer based on https://github.com/grpc/grpc/blob/master/doc/load-balancing.md and https://godoc.org/google.golang.org/grpc/balancer/grpclb/grpc_lb_v1 , it is working fairly well.

Currently, I am in a need to send a custom error code as the status code and custom error message as error message when the client tries to connect to a downstream service (through my Grpc LoadBalancer)

Essentially, I am trying to send through this Custom error code and message from the BalanceLoad(). The signature of the function is (part of LoadBalancerServer interface)

BalanceLoad(LoadBalancer_BalanceLoadServer) error

This method only allows throwing an error (which is essentially an error string) and I have seen the error it throws doesn't reach the client. How can I send my custom error message and code to the Grpc channel, so that client should receive my custom error not an error message like:

Grpc.Core.RpcException: Status(StatusCode=Unknown, Detail="Failed to create subchannel")

So instead of StatusCode = "Unknown", it will be my custom error code and the Detail will by my custom error message.

-- Gautam Moulik
grpc-go
kubernetes
load-balancing

0 Answers