Closed llucax closed 3 months ago
This is a port of:
With the following changes:
ClientError
to ApiClientError
to make it less ambiguous in contexts where there might be other types of clients (like a customer).grpcio
too, at the expense of type checks being deferred to runtime. This should be temporary though, until we can battle-test betterproto and decide if we do the switch or stay with grpcio. I tried a type-safe approach using generics but it was too intrusive, as we would have to explicitly mention the underlying grpc error type when using every exception, like OperationTimedOut[GrpclibError]
.GrpcError
: grpclib_error
and gprcio_error
to make it easier to access the underlying error for a particular library
Add a
ApiClientError
exception that is the base class for all client exceptions. This exception is raised when there is an error in the client. We also wrap all gRPC response errors in aGrpcError
exception that is a subclass ofApiClientError
, and add one subclass for each possible gRPC status code.This makes error handling more pythonic, as one can now just catch the exception type one is interested in, without having to do a second-level matching using the status.
It also helps avoiding to expose the grpclib classes to the user.