use std::borrow::Cow; pub(crate) type Result = core::result::Result; /// Custom error type for the Musixmatch client #[derive(thiserror::Error, Debug)] #[non_exhaustive] pub enum Error { /// Request rate-limited by Musixmatch #[error("You are sending requests too fast. Wait a minute and try again.")] Ratelimit, /// Musixmatch token expired #[error("The Musixmatch user token expired. Request a new one.")] TokenExpired, /// Musixmatch returned an error code #[error("Error {status_code} returned by the Musixmatch API. Message: '{msg}'")] MusixmatchError { /// Musixmatch status code status_code: u16, /// Error message msg: String, }, /// Client requires credentials, but none were given #[error("You did not input credentials")] MissingCredentials, /// Wrong Musixmatch credentials #[error("You entered wrong credentials")] WrongCredentials, /// Musixmatch content not found #[error("The requested content could not be found")] NotFound, /// Musixmatch content not available #[error("Unfortunately we're not authorized to show these lyrics")] NotAvailable, /// Musixmatch returned no data or the data that could not be deserialized #[error("JSON parsing error: {0}")] InvalidData(Cow<'static, str>), /// Error from the HTTP client #[error("http error: {0}")] Http(reqwest::Error), } impl From for Error { fn from(value: reqwest::Error) -> Self { // Dont leak the URL since it contains the session token Self::Http(value.without_url()) } } impl From for Error { fn from(value: serde_json::Error) -> Self { Self::InvalidData(value.to_string().into()) } } /// Could not parse Musixmatch FQID #[derive(thiserror::Error, Debug)] #[error("Could not parse Musixmatch FQID")] pub struct IdError;