#[non_exhaustive]pub enum Error {
Api(ApiError),
Transport(TransportError),
Decode {
path: String,
body: String,
source: Error,
},
Credentials(String),
InvalidRequest(String),
Stream(String),
InvalidUrl(String),
RetriesExhausted {
attempts: u32,
last: ApiError,
},
}Expand description
Anything that can go wrong while talking to Alpaca.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Api(ApiError)
Alpaca returned a non-success HTTP status.
Transport(TransportError)
The request never completed: DNS, TLS, connection, or timeout failure.
Decode
A response arrived but could not be deserialized into the expected type.
body carries the raw payload so the mismatch can be diagnosed without
re-issuing the request.
Fields
Credentials(String)
The supplied credentials are structurally invalid.
InvalidRequest(String)
A request was rejected locally, before any network call was made.
Stream(String)
A stream failed: the connection, the handshake, or a frame carried on it.
This covers both stream transports — the msgpack and JSON websockets and the SSE event streams — because the failures are the same shape and a caller matching on them is not usually asking which one broke.
The boundary against InvalidRequest is where
the failure happened, not what caused it. Anything the crate determines
locally before a socket is opened — an empty subscription set, a
non-positive timeout, an unrecognised feed — stays InvalidRequest.
Everything that fails on the wire is this.
A stream error is not necessarily the end of the stream. The market data stream reconnects from most of them and stops on the two that never resolve by retrying — a subscription the account is not entitled to, and credentials the server rejects.
InvalidUrl(String)
The configured base URL could not be joined with the request path.
RetriesExhausted
Every retry attempt returned a retryable status.
Carries the final ApiError so the caller still sees what Alpaca said.
Implementations§
Source§impl Error
impl Error
Sourcepub fn status(&self) -> Option<u16>
pub fn status(&self) -> Option<u16>
The HTTP status code, when the failure came from a response.
Sourcepub fn is_transient(&self) -> bool
pub fn is_transient(&self) -> bool
Whether this failure is transient — worth trying again if the request is safe to repeat.
Named for what it can actually tell you. The obvious reading of a method
called is_retryable is “it is safe to send this again”, and that is not
something an error alone can answer — which is why it is not called that.
Transient does not mean safe to replay. A timed-out POST /v2/orders
and a 504 on the same request are both transient, and both are
indistinguishable from an order Alpaca accepted whose response was lost;
replaying either places a second order. The one transport failure that
is safe is a connect error, because nothing was sent.
The safety question belongs to the request method, and the client answers
it internally: GET, PUT and DELETE are replayed, POST and PATCH
are not, except on a 429. If you are deciding whether to re-issue a call
yourself, that is the rule to apply — this predicate only tells you
whether trying again could plausibly work.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl !RefUnwindSafe for Error
impl !UnwindSafe for Error
impl Freeze for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more