Module error
Expand description
Map protocol errors to public connector errors.
Two mappings exist, and the difference matters:
map_protocol_errfor queries and subscriptions. A failure can be retried safely.map_command_errforplaceandcancel. Anything that may have reached the broker isError::Unknown, because a retry could create a second order.
| gRPC status | Query or stream | Command |
|---|---|---|
RESOURCE_EXHAUSTED | Error::RateLimited | Error::RateLimited |
UNAUTHENTICATED (and a login the broker refused) | Error::Config | Error::Config |
NOT_FOUND | Error::Rejected, code not_found | Error::Rejected, code not_found |
PERMISSION_DENIED, INVALID_ARGUMENT, FAILED_PRECONDITION, OUT_OF_RANGE, ALREADY_EXISTS, UNIMPLEMENTED | Error::Rejected | Error::Rejected |
anything else (UNAVAILABLE, DEADLINE_EXCEEDED, INTERNAL, …) | Error::Transport | Error::Unknown |
§Examples
use brokapi_core::Error;
use brokapi_finam::error::{map_command_err, map_protocol_err};
use brokapi_finam_protocol::FinamError;
use tonic::Code;
let lost = FinamError::Status { code: Code::Unavailable, message: "connection reset".into() };
// A read can simply be repeated.
assert!(matches!(map_protocol_err(&lost), Error::Transport(_)));
// A command may or may not have been applied.
assert!(matches!(map_command_err(&lost), Error::Unknown));
let refused = FinamError::Status { code: Code::InvalidArgument, message: "bad price".into() };
assert!(matches!(map_command_err(&refused), Error::Rejected { .. }));Functions§
- code_
name - Lowercase name of a gRPC status code (
invalid_argument), used as thecodeofError::Rejected. - map_
command_ err - Errors of
place/cancel: anything that may have reached the broker isUnknown, neverTransportorRejected. - map_
protocol_ err - Errors of queries and subscriptions. Commands use
map_command_err. - transport
- A [
Error::Transport] with a text. For failures of this process (a broken stream, an unknown subscription), not for answers of the broker. - unsupported
- An [
Error::Unsupported] naming the capability the broker does not offer (for examplereplace_order).