0

Google docs propose the following model (https://cloud.google.com/apis/design/errors#error_model) for sending rich errors in gRPC but it seems that the error string is sent to the user every time. What I want to do is to send a code and then map it to a string when it reaches the client.

What I want to know is whatever the proto3 language supports writing data so that I would use it client-side, without defining a custom structure for the purposes of mapping error codes to error messages.

dclipca
  • 1,739
  • 1
  • 16
  • 51
  • 2
    The error string is sent on every error. Is that such an expensive thing that you can't afford to sent it when errors are encountered? Maybe measure whether it has an impact before worrying about it. – Marc Sep 28 '20 at 11:26
  • @Marc I am using this for an app where bandwidth is very important. I can send the string over the connection without problems but the users would connect via smartphones, most of the time being in locations that do not have any Wi-Fi. I also want to use this not only for error handling but also for other functionalities. – dclipca Sep 28 '20 at 11:32
  • I do not think this will be such a big overhead also using this you can easily update error on server without needing a client side update – Shubham Srivastava Sep 28 '20 at 11:54
  • Errors should be rare. Optimizing them is probably a waste of time. If they aren't rare, you probably need a different application design. – Jonathan Hall Sep 28 '20 at 12:05
  • You're all probably right. I will still use this pattern for transmitting data that doesn't change and is encountered frequently. – dclipca Sep 28 '20 at 12:56

1 Answers1

2

In your proto definition, define a simple enum with any extra error codes:

enum extraStatusCode {
    UNKNOWN         = 0;  // not set/used
    TOO_MANY_FOOS   = 1;
    NOT_ENOUGH_BARS = 2;
}

And include it as a top-level field in any returned message:

message User {
    string uid      = 1;
    string email    = 2;

    // ...

    extraStatusCode = 15;
}

if a message is sent with a non-zero extraStatusCode - then an edge case was encountered.

colm.anseo
  • 19,337
  • 4
  • 43
  • 52