In our case, if srv1 returns error an exception will be caught which cause srv2 and srv3 not being called. So my question is, should our service return error which cause the clients terminated, or should our service always return nil but give rsp.Code and rsp.Msg instead which enable the clients to call srv2 and srv3 even if srv1 failed ? or there are some better ways for the server and client to handle errors?
For starters, this has nothing to do with Go but with gRPC, so I don’t think it’s the best place to be discussing it. Anyway, my 2 cents:
That’s because you’re throwing everything inside the same try, which isn’t necessary. If you think you can go on calling next services after one failed, then handle each one separately. It’s not that "rsp.Code and rsp.Msg instead … enable the clients to call srv2 and srv3 even if srv1 failed", is how you handle the errors that enables the subsequent calls: if you actually got an Err_Code from srv1 (with a nil error), how would you handle it and would you continue to call the other services? That’s logic that depends on your application.
On the other hand, what’s the point of having a function return an error if you’ll always return nil?
For what is worth, I would return errors from the services and then handle them properly at the client.