Skip to main content

OpenFIGIError

Enum OpenFIGIError 

Source
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.

Fields

§kind: OtherErrorKind

Error classification

§message: String

Error description

Implementations§

Source§

impl OpenFIGIError

Source

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);
    }
}
Source

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
}
Source

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.

Source

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.

Source

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.

Source

pub fn is_builder(&self) -> bool

Returns true if this error originated from the builder methods.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for OpenFIGIError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for OpenFIGIError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for OpenFIGIError

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for OpenFIGIError

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for OpenFIGIError

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for OpenFIGIError

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for OpenFIGIError

Source§

fn from(e: ParseError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more