gobgp icon indicating copy to clipboard operation
gobgp copied to clipboard

Consider using grpc error codes for grpc API responses

Open jvgutierrez opened this issue 4 months ago • 1 comments

Hi, I've realized that gobgp grpc API doesn't make use of grpc status codes when returning errors, so clients need to parse the status message string to be able which kind of error received instead of just checking the status code.

So instead of

    if _, err := client.DeletePolicy(ctx, policyRequest); status.Code(err) != codes.NotFound {
        // handle error
    }   

The client needs to check the status string:

    if _, err := client.DeletePolicy(ctx, policyRequest); err != nil {
        s, ok := status.FromError(err)
        if !ok || !strings.HasPrefix(s.Message(), "not found") {
            // handle error
        }
    }

Would it be feasible to adopt grpc status codes? Thanks!

jvgutierrez avatar Sep 27 '24 04:09 jvgutierrez