Skip to main content

Module error

Module error 

Source
Expand description

Map protocol errors to public connector errors.

Two mappings exist, and the difference matters:

  • map_protocol_err for queries and subscriptions. A failure can be retried safely.
  • map_command_err for place and cancel. Anything that may have reached the broker is Error::Unknown, because a retry could create a second order.
gRPC statusQuery or streamCommand
RESOURCE_EXHAUSTEDError::RateLimitedError::RateLimited
UNAUTHENTICATED (and a login the broker refused)Error::ConfigError::Config
NOT_FOUNDError::Rejected, code not_foundError::Rejected, code not_found
PERMISSION_DENIED, INVALID_ARGUMENT, FAILED_PRECONDITION, OUT_OF_RANGE, ALREADY_EXISTS, UNIMPLEMENTEDError::RejectedError::Rejected
anything else (UNAVAILABLE, DEADLINE_EXCEEDED, INTERNAL, …)Error::TransportError::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 the code of Error::Rejected.
map_command_err
Errors of place / cancel: anything that may have reached the broker is Unknown , never Transport or Rejected.
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 example replace_order).