#[cfg(feature = "oauth")]
use std::time::Duration;
use reqwest::StatusCode;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("invalid base URL: {0}")]
InvalidBaseUrl(#[from] url::ParseError),
#[error("base URL cannot be used for hierarchical API paths: {0}")]
NonHierarchicalBaseUrl(String),
#[error("invalid API path segment: {0:?}")]
InvalidPathSegment(String),
#[error("failed to build the HTTP client: {0}")]
BuildClient(reqwest::Error),
#[error("invalid HTTP header value: {0}")]
InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue),
#[error("HTTP request failed: {0}")]
Http(#[from] reqwest::Error),
#[error("Yandex Music API error (HTTP {status}): {message}")]
Api {
status: StatusCode,
message: String,
body: Option<serde_json::Value>,
},
#[error("playlist revision conflict (expected revision {expected_revision}): {message}")]
PlaylistRevisionConflict {
expected_revision: u64,
message: String,
body: Option<serde_json::Value>,
},
#[error("failed to serialize API request: {0}")]
SerializeRequest(#[from] serde_json::Error),
#[cfg(feature = "downloads")]
#[error("invalid download request: {0}")]
InvalidDownloadRequest(String),
#[cfg(feature = "downloads")]
#[error("track download is unavailable ({name}): {message}")]
DownloadUnavailable { name: String, message: String },
#[cfg(any(feature = "downloads", feature = "lyrics"))]
#[error("system clock is before the Unix epoch")]
InvalidSystemClock,
#[cfg(feature = "lyrics")]
#[error("track ID {0:?} cannot be signed for the lyrics endpoint")]
InvalidLyricsTrackId(String),
#[cfg(feature = "oauth")]
#[error(
"Yandex OAuth error (HTTP {status}): {code}{description}",
description = description
.as_deref()
.map(|value| format!(": {value}"))
.unwrap_or_default()
)]
OAuth {
status: StatusCode,
code: String,
description: Option<String>,
body: Option<serde_json::Value>,
},
#[cfg(feature = "oauth")]
#[error("device authorization timed out after {timeout:?}")]
DeviceAuthorizationTimedOut { timeout: Duration },
#[error("invalid API response: {message}")]
InvalidResponse {
message: String,
#[source]
source: Option<serde_json::Error>,
},
}
pub type Result<T> = std::result::Result<T, Error>;