#[non_exhaustive]pub enum Error {
Show 19 variants
InvalidBaseUrl(String),
UrlNotABase {
url: String,
},
Http(Error),
UpstreamStatus {
endpoint: &'static str,
status: u16,
body_preview: Option<String>,
},
Unknown {
endpoint: &'static str,
},
Decode {
endpoint: String,
status: u16,
message: String,
},
BadRequest(String),
MissingQuery {
name: &'static str,
},
Header {
name: &'static str,
source: InvalidHeaderValue,
},
Api(Box<dyn Error + Send + Sync + 'static>),
SymbolNotFound {
symbol: String,
},
BadConid {
symbol: String,
raw: String,
source: ParseIntError,
},
WsHandshake {
url: String,
source: Error,
},
WsTransport {
source: Error,
},
WsProtocol(String),
ResponseBuild(String),
NotAuthenticated,
NoSession,
Other(String),
}Expand description
Errors that can arise when talking to the Client Portal Gateway.
The enum is #[non_exhaustive] — match on the variants you care about
and handle the rest via a catch-all so adding new variants in a point
release is not a breaking change.
§Retry hints
Use Error::is_retryable in retry loops rather than pattern-matching
every variant. Transient transport failures, upstream 5xx, and
NoSession are flagged retryable; caller-input errors and auth
failures are not.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
InvalidBaseUrl(String)
The base URL passed to Client::new could not be parsed.
UrlNotABase
A URL we tried to manipulate isn’t suitable as a base — either
the scheme can’t have a hierarchical path (data:, mailto:)
or the URL has no host. Distinct from Error::InvalidBaseUrl
because it surfaces during a call rather than at builder time.
Http(Error)
HTTP transport failure (DNS, connection, TLS, timeouts).
UpstreamStatus
CPGateway returned a non-2xx status. Carries the endpoint name,
the upstream status code, and (where cheap) a short body preview.
Replaces a swathe of older Error::Other("upstream 500")-style
sites — callers can now branch on .status for retry logic.
Fields
Unknown
CPGateway returned a status code our typed client doesn’t model. Useful canary for OpenAPI spec drift — when a previously-undocumented status appears in production, this surfaces the endpoint name so telemetry can flag it without losing every detail to a string.
Decode
A JSON response body could not be decoded into the expected type — typically a sign the Gateway sent an HTML error page on top of a 2xx status (Akamai error pages, maintenance banners, etc.).
Fields
BadRequest(String)
Caller-provided input was malformed (bad query parameter, oversize
body, unparseable URL, etc.). Distinct from Error::Other so
HTTP wrappers can map it to 400 rather than 500.
MissingQuery
A required query parameter was absent. Distinct from
Error::BadRequest so HTTP wrappers can map to a more specific
error code and so callers can hint the user about what’s missing.
Header
HTTP header construction failed — the value contained bytes the
http crate refuses to put on the wire (control chars, non-visible
ASCII, CR/LF). Carries the header name + the underlying parse error.
Fields
source: InvalidHeaderValueThe underlying value-validation failure.
Api(Box<dyn Error + Send + Sync + 'static>)
An error bubbled up from the generated API layer. The inner
boxed error is whatever the generated client raised — this keeps
bezant-core’s public API free of a versioned anyhow type.
SymbolNotFound
Symbol → conid lookup returned no contracts. Distinct from
Error::UpstreamStatus because the upstream returned a
well-formed empty result, not a failure.
BadConid
A contract IBKR returned for a symbol carried a conid that
couldn’t be parsed as i32 — surfaces as a typed signal so
callers don’t have to string-match on Error::Other.
Fields
source: ParseIntErrorThe underlying parse error.
WsHandshake
WebSocket handshake (HTTP upgrade) failed. Carries the URL we were upgrading to plus the underlying tungstenite error so a caller can branch on TLS vs DNS vs auth failures.
Fields
WsTransport
WebSocket transport (read/write/close) failed mid-stream.
WsProtocol(String)
WebSocket protocol violation or bezant-side serialisation issue.
ResponseBuild(String)
Failed to construct an HTTP response — body assembly or header validation. Server-side internal; shouldn’t be observable in normal operation.
NotAuthenticated
The Gateway reports we are not authenticated — the user needs to log in via the Gateway’s browser UI.
NoSession
The Gateway is reachable but has no active session (e.g. was just booted, or session was invalidated by another login).
Other(String)
A catch-all for unexpected conditions that don’t fit other variants. Prefer adding a typed variant — this is the documented escape hatch of last resort, and is mapped to a generic 500 at the HTTP boundary.
Implementations§
Source§impl Error
impl Error
Sourcepub fn other(msg: impl Into<String>) -> Self
pub fn other(msg: impl Into<String>) -> Self
Construct a free-form error.
Prefer a typed variant — Error::Other maps to a generic 500 at
the HTTP boundary and gives callers no programmatic handle.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Hint for retry loops: returns true iff this error might
succeed on retry. Use this in backoff loops instead of
pattern-matching every variant by hand.
Retryable:
- Transport timeouts / connect failures / general request errors
- Upstream 5xx and 429 (rate-limited)
NoSession(session may come back)- WebSocket transport failures (reconnect)
Not retryable:
- Caller-input errors (
BadRequest,MissingQuery,InvalidBaseUrl,UrlNotABase) - Auth failures (
NotAuthenticated) SymbolNotFound,BadConid,Header(data-shape problems)Decode/Api/Unknown(semantically broken response)Other(unknown — be conservative, don’t retry)
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 Freeze for Error
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl !UnwindSafe 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
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.