#[non_exhaustive]pub enum SerpError {
MissingApiKey,
ClientBuilder(String),
RequestFailed(Error),
InvalidResponse(String),
RateLimited {
retry_after: u64,
},
ApiError {
code: u16,
message: String,
},
Serialization(Error),
UrlEncoding(Error),
InvalidParameter(String),
Timeout,
Network(String),
}
Expand description
Comprehensive error types for SerpAPI SDK operations.
This enum covers all possible error conditions that can occur when using the SDK, from configuration issues to network problems and API-specific errors.
§Examples
use serp_sdk::{SerpClient, SerpError};
// Handle specific error types
match SerpClient::builder().build() {
Ok(client) => println!("Client created successfully"),
Err(SerpError::MissingApiKey) => {
println!("Please set SERP_API_KEY environment variable");
}
Err(e) => println!("Other error: {}", e),
}
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
MissingApiKey
API key not provided via builder or environment variable.
Set the API key using SerpClientBuilder::api_key
or the SERP_API_KEY
environment variable.
ClientBuilder(String)
Error during HTTP client construction.
This typically indicates an issue with the underlying HTTP client configuration, such as invalid TLS settings or proxy configuration.
RequestFailed(Error)
HTTP request failed.
This wraps underlying reqwest::Error
and can indicate network connectivity issues,
DNS resolution failures, or connection timeouts.
InvalidResponse(String)
Response could not be parsed or has invalid format.
This occurs when the API returns a response that doesn’t match the expected JSON structure, which might indicate API changes or corrupted responses.
RateLimited
Rate limit exceeded, with retry-after duration.
SerpAPI has rate limits. When exceeded, this error includes the number of seconds to wait before retrying. The SDK’s retry logic handles this automatically.
ApiError
API returned an error response.
This represents HTTP error status codes (4xx, 5xx) returned by the SerpAPI service, such as authentication failures or server errors.
Serialization(Error)
JSON serialization/deserialization error.
This wraps serde_json::Error
and occurs when request parameters cannot be
serialized or response data cannot be deserialized.
UrlEncoding(Error)
URL encoding error.
This occurs when query parameters cannot be properly URL-encoded, typically due to invalid characters in parameter values.
InvalidParameter(String)
Invalid query parameter.
This is thrown when query parameters fail validation, such as setting a limit outside the valid range (1-100).
Timeout
Timeout during request execution.
The request exceeded the configured timeout duration.
Adjust the timeout using SerpClientBuilder::timeout
.
Network(String)
Network connectivity issues.
This represents lower-level network problems that don’t fit into other categories, such as proxy failures or DNS issues.
Trait Implementations§
Source§impl Error for SerpError
impl Error for SerpError
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
Auto Trait Implementations§
impl Freeze for SerpError
impl !RefUnwindSafe for SerpError
impl Send for SerpError
impl Sync for SerpError
impl Unpin for SerpError
impl !UnwindSafe for SerpError
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.