Skip to content

Consider using grpc error codes for grpc API responses #2837

@jvgutierrez

Description

@jvgutierrez

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions