pub fn map_status(status: &Status) -> ErrorExpand description
Status of a read-only call (snapshots, reference data).
ResourceExhaustedgives [Error::RateLimited], withretry_aftertaken from thex-ratelimit-resetheader (seconds), else 1 s (60 s for the codes 80003 and 80006, which the broker counts per minute). Except the codes that are not a limit of time: 80001, 80004, 80005 and 80007 give [Error::Rejected] with the codestreams_limit,no_subscriptions,stream_lifetimeorstop_orders_limit, because a repeat cannot help.InvalidArgumentwith the code 30261 (too many stop orders in the answer) gives [Error::Rejected] with the codestop_orders_response_limit.NotFoundgives [Error::Rejected] with the codenot_found([brokapi_core::NOT_FOUND], the same at every broker).InvalidArgument,PermissionDenied,FailedPrecondition,Unimplemented,AlreadyExists,OutOfRangegives [Error::Rejected], with the status code name ascode(for example"InvalidArgument") and the status message asmessage.Unauthenticatedgives [Error::Config]: the token is wrong or expired, fix it.- everything else (
Unavailable,DeadlineExceeded,Internal, …) gives [Error::Transport].
§Examples
use brokapi_core::Error;
use brokapi_tbank::error::map_status;
use tonic::Status;
match map_status(&Status::not_found("50002")) {
Error::Rejected { code, message } => {
assert_eq!(code, "not_found");
assert_eq!(message, "50002");
}
other => panic!("unexpected {other:?}"),
}
assert!(matches!(map_status(&Status::resource_exhausted("80002")), Error::RateLimited { .. }));
// 80007 is a business refusal, not a limit of time.
match map_status(&Status::resource_exhausted("80007")) {
Error::Rejected { code, .. } => assert_eq!(code, "stop_orders_limit"),
other => panic!("unexpected {other:?}"),
}
assert!(matches!(map_status(&Status::unauthenticated("40003")), Error::Config(_)));