pub enum OpenFIGIError {
ReqwestError(Error),
ReqwestMiddlewareError(Error),
UrlParseError(ParseError),
SerdeError(Error),
IoError(Error),
ResponseError(ResponseContent),
OtherError {
kind: OtherErrorKind,
message: String,
},
}Expand description
Main error type for all OpenFIGI API operations.
This enum unifies all possible error types that can occur during OpenFIGI API interactions, providing a single error type for consistent handling across the entire crate. Each variant wraps a specific error type while maintaining the original error information.
§Design Philosophy
Rather than requiring consumers to handle multiple error types, OpenFIGIError
provides a unified interface with convenient inspection methods. This allows
for both simple error handling (treat all errors the same) and sophisticated
error handling (inspect specific error types).
§Inspection Methods
The error type provides numerous is_*() methods to check error categories
without pattern matching on variants. This makes error handling more ergonomic
and future-proof as new error variants can be added without breaking existing code.
§Examples
use openfigi_rs::error::OpenFIGIError;
async fn handle_request_error(err: OpenFIGIError) {
match err.status() {
Some(status) if status.is_client_error() => {
eprintln!("Client error {}: check request parameters", status);
}
Some(status) if status.is_server_error() => {
eprintln!("Server error {}: retry may help", status);
}
None if err.is_timeout() => {
eprintln!("Request timeout: retry with backoff");
}
None if err.is_connect() => {
eprintln!("Connection error: check network connectivity");
}
_ => {
eprintln!("Other error: {}", err);
}
}
}Variants§
ReqwestError(Error)
HTTP client error from the underlying reqwest library.
Includes network issues, timeout errors, connection failures, and other HTTP-level problems.
ReqwestMiddlewareError(Error)
Middleware stack error from reqwest-middleware.
Occurs when middleware components (retry policies, logging, etc.) fail or when the middleware stack itself encounters issues.
UrlParseError(ParseError)
URL parsing error when constructing request URLs.
Typically indicates malformed base URLs or invalid URL components.
SerdeError(Error)
JSON serialization or deserialization error.
Occurs when request payloads cannot be serialized or when response bodies cannot be parsed as valid JSON.
IoError(Error)
File system I/O error for operations like caching or logging.
May occur during file-based operations if implemented in the future.
ResponseError(ResponseContent)
HTTP response error with detailed status and content information.
Contains structured error information from the OpenFIGI API, including status codes and response body content.
OtherError
Miscellaneous application-specific errors.
Used for validation errors and other issues that don’t fit into the other categories.
Implementations§
Source§impl OpenFIGIError
impl OpenFIGIError
Sourcepub fn url(&self) -> Option<&Url>
pub fn url(&self) -> Option<&Url>
Returns the URL associated with this error, if available.
Provides access to the request URL for errors that occurred during HTTP operations. Useful for debugging and logging.
§Examples
use openfigi_rs::error::OpenFIGIError;
fn log_error_with_url(err: &OpenFIGIError) {
if let Some(url) = err.url() {
eprintln!("Error occurred for URL: {}", url);
}
}Sourcepub fn url_mut(&mut self) -> Option<&mut Url>
pub fn url_mut(&mut self) -> Option<&mut Url>
Returns a mutable reference to the URL for this error.
Useful for removing sensitive information from URLs before logging or displaying errors to users.
§Examples
use openfigi_rs::error::OpenFIGIError;
fn sanitize_error_url(mut err: OpenFIGIError) -> OpenFIGIError {
if let Some(url) = err.url_mut() {
url.set_query(None); // Remove query parameters
}
err
}Sourcepub fn with_url(self, url: Url) -> Self
pub fn with_url(self, url: Url) -> Self
Returns a new error with the specified URL attached.
Attaches URL information to errors that support it. Only applies to reqwest and middleware errors; other error types are returned unchanged.
Sourcepub fn without_url(self) -> Self
pub fn without_url(self) -> Self
Returns an error with the URL removed for security purposes.
Removes URL information from errors that contain it. Useful when URLs might contain sensitive information that shouldn’t be logged.
Sourcepub fn is_middleware(&self) -> bool
pub fn is_middleware(&self) -> bool
Returns true if this error originated from middleware.
Identifies errors that occurred within the middleware stack, such as retry policy exhaustion or middleware-specific failures.
Sourcepub fn is_builder(&self) -> bool
pub fn is_builder(&self) -> bool
Returns true if this error originated from the builder methods.
Sourcepub fn is_redirect(&self) -> bool
pub fn is_redirect(&self) -> bool
Returns true if this error is a redirect error.
Identifies errors related to HTTP redirects, such as too many redirects or redirect loops.
Sourcepub fn is_status(&self) -> bool
pub fn is_status(&self) -> bool
Returns true if this error is a status error.
Indicates errors that contain HTTP status codes, either from reqwest or from explicit response errors.
Sourcepub fn is_timeout(&self) -> bool
pub fn is_timeout(&self) -> bool
Returns true if this error is a timeout error.
Indicates that the HTTP request exceeded the configured timeout period. This can help distinguish between connection issues and slow responses.
Sourcepub fn is_request(&self) -> bool
pub fn is_request(&self) -> bool
Returns true if this error is a request error.
Indicates errors that occurred during request processing, such as malformed request data or invalid parameters.
Sourcepub fn is_connect(&self) -> bool
pub fn is_connect(&self) -> bool
Returns true if this error is a connection error.
Indicates network-level connection failures, such as DNS resolution problems, connection refused, or network unreachable errors.
Sourcepub fn is_body(&self) -> bool
pub fn is_body(&self) -> bool
Returns true if this error is related to the request or response body.
Identifies errors that occurred during body processing, such as reading response bodies or serializing request payloads.
Sourcepub fn is_decode(&self) -> bool
pub fn is_decode(&self) -> bool
Returns true if this error is a decode error.
Indicates errors that occurred during response deserialization or other data decoding operations. Includes JSON parsing failures and format conversion errors.
Sourcepub fn status(&self) -> Option<StatusCode>
pub fn status(&self) -> Option<StatusCode>
Returns the HTTP status code associated with this error, if available.
Extracts the HTTP status code from errors that contain one, such as
reqwest errors with status information or explicit response errors.
Returns None for errors that don’t have an associated status code.
§Examples
use openfigi_rs::error::OpenFIGIError;
fn handle_status_error(err: &OpenFIGIError) {
if let Some(status) = err.status() {
match status.as_u16() {
400 => eprintln!("Bad request - check parameters"),
401 => eprintln!("Unauthorized - check API key"),
429 => eprintln!("Rate limited - retry later"),
500..=599 => eprintln!("Server error - retry may help"),
_ => eprintln!("HTTP error: {}", status),
}
}
}Trait Implementations§
Source§impl Debug for OpenFIGIError
impl Debug for OpenFIGIError
Source§impl Display for OpenFIGIError
impl Display for OpenFIGIError
Source§impl Error for OpenFIGIError
impl Error for OpenFIGIError
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()
Source§impl From<Error> for OpenFIGIError
impl From<Error> for OpenFIGIError
Source§impl From<Error> for OpenFIGIError
impl From<Error> for OpenFIGIError
Source§impl From<Error> for OpenFIGIError
impl From<Error> for OpenFIGIError
Source§impl From<Error> for OpenFIGIError
impl From<Error> for OpenFIGIError
Source§impl From<ParseError> for OpenFIGIError
impl From<ParseError> for OpenFIGIError
Source§fn from(e: ParseError) -> Self
fn from(e: ParseError) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for OpenFIGIError
impl !UnwindSafe for OpenFIGIError
impl Freeze for OpenFIGIError
impl Send for OpenFIGIError
impl Sync for OpenFIGIError
impl Unpin for OpenFIGIError
impl UnsafeUnpin for OpenFIGIError
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<T> ErasedDestructor for Twhere
T: 'static,
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.