pub fn map_command_err(err: BcsApiError) -> ErrorExpand description
A command that failed: only answers that prove the broker did not act become definite errors.
No answer, a break, HTTP 5xx or an unreadable answer may have reached the broker: Error::Unknown,
never retried by the library.
| Protocol error | Public error |
|---|---|
HttpError without a status (no answer, a break, a timeout) or with status 500 and above | [Error::Unknown] |
ParseError (the answer cannot be read), WsError | [Error::Unknown] |
HttpError with status 400 to 499, except 429 | [Error::Rejected] with code http_<status> and the broker’s message |
everything else (429, AuthError, NotFound, ValidationError, …) | as in map_err |
Note that ValidationError (the usual way BCS refuses an order) is [Error::Rejected] with code
validation, and that NotFound is [Error::Rejected] with code not_found, as in map_err.
§Examples
use brokapi_bcs_protocol::error::BcsApiError;
use brokapi_bcs::error::map_command_err;
use brokapi_core::Error;
// No answer at all: the order may exist.
let lost = BcsApiError::HttpError { status: None, message: "timeout".into(), trace_id: None };
assert!(matches!(map_command_err(lost), Error::Unknown));
// The broker answered 503: it may have acted.
let busy = BcsApiError::HttpError { status: Some(503), message: "busy".into(), trace_id: None };
assert!(matches!(map_command_err(busy), Error::Unknown));
// The broker answered 403: it did nothing.
let denied = BcsApiError::HttpError { status: Some(403), message: "no".into(), trace_id: None };
match map_command_err(denied) {
Error::Rejected { code, .. } => assert_eq!(code, "http_403"),
other => panic!("{other:?}"),
}