use sellapp::resources::products::ListParams;
use sellapp::{Client, Error};
pub async fn handle_error(client: &Client) -> Result<String, Error> {
match client
.products()
.list(ListParams {
limit: Some(1),
..Default::default()
})
.await
{
Ok(page) => Ok(format!("Read {} product(s)", page.data.len())),
Err(Error::Authentication(error)) => Ok(format!(
"API status {}: {} (request {})",
error.status,
error.message,
error.request_id.as_deref().unwrap_or("unavailable")
)),
Err(Error::Api(error)) => Ok(format!(
"API status {}: {} (request {})",
error.status,
error.message,
error.request_id.as_deref().unwrap_or("unavailable")
)),
Err(Error::Timeout(message)) => Ok(format!("Request timed out: {message}")),
Err(error) => Err(error),
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let base_url = std::env::var("SELLAPP_API_BASE_URL")?;
let client = Client::from_env()?
.with_base_url(base_url)
.with_max_retries(0);
println!("{}", handle_error(&client).await?);
Ok(())
}