pub fn map_err(err: AlorApiError) -> ErrorExpand description
Maps a failed read (or a failed step before a command was sent) to a public error.
| Protocol error | Public error |
|---|---|
RateLimitExceeded, or Http with status 429 | [Error::RateLimited] with retry_after of 1 second (the broker does not say how long: the value is a fixed guess) |
Auth (the token is refused) | [Error::Config] with the broker’s message: fix the token, a repeat will not help |
Subscription, Ws, Parse | [Error::Transport] with the message |
Http (any other status or no status) | [Error::Transport] with the message |
NotFound (HTTP 404) | [Error::Rejected] with code not_found (an unknown instrument or order, as at the other brokers) |
All [Error::Transport] results are retryable for a read. Do not use this function for a command: it would
turn a lost answer into a plain transport error. Use map_command_err.
§Examples
use brokapi_alor_protocol::error::AlorApiError;
use brokapi_alor::error::map_err;
use brokapi_core::Error;
assert!(matches!(map_err(AlorApiError::RateLimitExceeded), Error::RateLimited { .. }));
assert!(map_err(AlorApiError::NotFound { message: "no".into() }).is_not_found());
assert!(matches!(map_err(AlorApiError::Auth { message: "bad token".into() }), Error::Config(_)));