#[non_exhaustive]pub enum ClientError {
Status(Status),
InvalidRequest(CallFailure),
NotProcessed(CallFailure),
Connection {
request_sent: bool,
failure: CallFailure,
},
StreamFailed(CallFailure),
NotGrpc(NotGrpc),
InvalidResponse(CallFailure),
DeadlineExceeded(CallFailure),
}Expand description
Why a call failed.
Built-in transports return it wrapped in ntex_error::Error, which
derefs to ClientError, so match on &*err.
Each variant calls for a different reaction from a caller that retries
calls or tracks the health of endpoints. Within a variant,
message() describes the cause, and
status() gives the gRPC code of every variant.
| Variant | Server saw the request? | What a caller can do |
|---|---|---|
Status | yes | apply the rules for the code |
InvalidRequest | no | fail the call, retrying fails the same way |
NotProcessed | no | retry at once, for any method |
Connection | maybe, see request_sent | retry elsewhere |
StreamFailed | maybe | retry if the method is idempotent |
NotGrpc | not by a grpc server | check the address, or back off on 429, 502, 503 and 504 |
InvalidResponse | yes | fail the call, asking again gets the same answer |
DeadlineExceeded | maybe | the time for the call is up |
match req.send().await {
// `req` comes from a generated client, e.g. `client.say_hello(&msg)`
Ok(res) => println!("{}", res.message),
Err(err) => match &*err {
// the server replied, but not with OK
ClientError::Status(st) => println!("{:?}: {}", st.code, err.message()),
// safe to retry, the server did not process the request
ClientError::NotProcessed(_) => println!("retry"),
_ => println!("call failed with {:?}: {err}", err.status()),
},
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Status(Status)
The server replied with a grpc-status other than OK.
The only variant that holds a status the server sent, including
DEADLINE_EXCEEDED.
InvalidRequest(CallFailure)
The request is not valid, nothing was sent and sending it again fails the same way.
A header with an invalid name or value (see
RequestContext::take_error()), headers over the server’s limit, a
message over Request::max_send_message_size() or a message that
does not compress.
NotProcessed(CallFailure)
The server did not process the request, retrying is safe for any method.
The connection was closing or out of stream identifiers when the call
started, the server refused the stream with REFUSED_STREAM, or the
server’s GOAWAY did not cover the stream.
Connection
The connection could not be established, or it failed or closed before the call ended.
Fields
request_sent: boolWhether the request was handed to the connection.
If false the server did not see the request and retrying is safe for any method, otherwise the server may have processed it.
failure: CallFailureThe failure, its source is the ntex-h2 error.
StreamFailed(CallFailure)
The stream of the call failed while the connection stayed up.
The server reset it, or broke the protocol on it, or the client reset
it because it could not send. The server may have processed the
request. A reset is mapped to a code as the gRPC spec says, e.g.
CANCEL to CANCELLED and ENHANCE_YOUR_CALM to
RESOURCE_EXHAUSTED.
NotGrpc(NotGrpc)
Something other than a grpc server replied: the HTTP status is not 200
or the content-type is not application/grpc.
InvalidResponse(CallFailure)
The server replied with a grpc response the client cannot accept.
The response has an invalid or no grpc-status, ends without
trailers or a complete message, has data after the message, a message
over Request::max_message_size(), in an unknown encoding or that
does not decode.
DeadlineExceeded(CallFailure)
The request timeout ran out before the server replied.
The client stopped waiting, the stream is reset with CANCEL then,
or the server reset the stream with CANCEL once the timeout had run
out. A DEADLINE_EXCEEDED status from the server is a
Status.
Implementations§
Source§impl ClientError
impl ClientError
Sourcepub fn status(&self) -> GrpcStatus
pub fn status(&self) -> GrpcStatus
The gRPC code of the failure.
The server’s code for Status, the code the HTTP
status maps to for NotGrpc and
CallFailure::code otherwise.
Trait Implementations§
Source§impl Clone for ClientError
impl Clone for ClientError
Source§impl Debug for ClientError
impl Debug for ClientError
Source§impl Display for ClientError
impl Display for ClientError
Source§impl Error for ClientError
impl Error for ClientError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()