#[non_exhaustive]pub enum HttpError {
Network(String),
Status {
status: u16,
message: String,
},
RateLimited {
retry_after_seconds: u64,
},
Timeout,
Cors {
message: String,
remediation: String,
},
}Expand description
HTTP client errors with retry classification.
Categorizes HTTP errors for proper retry handling:
- Network errors and timeouts are retryable
- 5xx server errors are retryable
- 429 rate limit responses include
retry_after_seconds - 4xx client errors are non-retryable
- CORS errors (WASM only) with remediation hints
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Network(String)
Network connectivity error (retryable)
Status
HTTP status error
RateLimited
Rate limited (retryable with backoff)
Timeout
Request timeout (retryable)
Cors
CORS error (WASM only, not retryable)
This error occurs when the browser blocks a cross-origin request. The IDP server must include proper CORS headers for the SDK to work in browsers.
Implementations§
Source§impl HttpError
impl HttpError
Sourcepub const fn is_retryable(&self) -> bool
pub const fn is_retryable(&self) -> bool
Check if this error is retryable.
Returns true for:
- Network errors
- Timeouts
- 5xx server errors
- Rate limiting (after waiting)
CORS errors are NOT retryable - they require server configuration changes.
Sourcepub const fn is_rate_limited(&self) -> bool
pub const fn is_rate_limited(&self) -> bool
Check if this error indicates rate limiting.
Sourcepub const fn retry_after(&self) -> Option<u64>
pub const fn retry_after(&self) -> Option<u64>
Get retry-after seconds if rate limited.
Sourcepub const fn rate_limited(retry_after_seconds: u64) -> Self
pub const fn rate_limited(retry_after_seconds: u64) -> Self
Create a rate limited error.
Sourcepub const fn suggested_retry_delay_ms(&self) -> Option<u64>
pub const fn suggested_retry_delay_ms(&self) -> Option<u64>
Get suggested retry delay in milliseconds.
Returns appropriate delay based on error type:
- Network errors: 500ms (short delay, transient issues)
- Timeout: 1000ms (moderate delay)
- 5xx errors: 2000ms (server needs time to recover)
- Rate limited:
retry_after_seconds * 1000(respect server’s hint) - 4xx errors: None (not retryable)
- CORS errors: None (requires server configuration)
Sourcepub const fn status_code(&self) -> Option<u16>
pub const fn status_code(&self) -> Option<u16>
Get the HTTP status code if this is a status error.
Sourcepub fn cors(message: impl Into<String>, origin: &str) -> Self
pub fn cors(message: impl Into<String>, origin: &str) -> Self
Create a CORS error with remediation hints.
Use this when a request fails due to CORS policy in WASM environments.
§Example
use lastid_sdk::HttpError;
let err = HttpError::cors(
"Request blocked by CORS policy",
"https://human.lastid.co",
);
assert!(!err.is_retryable());Trait Implementations§
Source§impl Error for HttpError
impl Error for HttpError
1.30.0 · 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<HttpError> for LastIDError
impl From<HttpError> for LastIDError
Auto Trait Implementations§
impl Freeze for HttpError
impl RefUnwindSafe for HttpError
impl Send for HttpError
impl Sync for HttpError
impl Unpin for HttpError
impl UnsafeUnpin for HttpError
impl UnwindSafe for HttpError
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.