use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("ipdata: HTTP {status}: {message}")]
Api { status: u16, message: String },
#[error("ipdata: request failed: {0}")]
Transport(String),
#[error("ipdata: failed to decode response: {0}")]
Decode(String),
}
pub(crate) fn api_error_message(body: &str) -> String {
#[derive(serde::Deserialize)]
struct ErrBody {
#[serde(default)]
error: String,
}
match serde_json::from_str::<ErrBody>(body) {
Ok(e) if !e.error.is_empty() => e.error,
_ => body.to_string(),
}
}