pandora_api/errors.rs
1//! Crate-level error types for the Pandora API.
2// SPDX-License-Identifier: MIT
3use crate::json::errors::JsonError;
4
5use thiserror::Error;
6
7/// A general, crate-wide result type.
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Error type capturing the full range of errors that can arise in the use of
11/// this API. The PandoraJsonRequestError variant wraps a separate error type
12/// (json::errors::JsonError) that captures errors returned by the Pandora
13/// JSON API.
14#[derive(Error, Debug)]
15pub enum Error {
16 /// Wraps serde_json serialization/deserialization errors
17 #[error("JSON serialization error: {0}")]
18 JsonSerializationError(#[from] serde_json::error::Error),
19 /// Wraps reqwest errors
20 #[error("HTTP I/O error: {0}")]
21 HttpIoError(#[from] reqwest::Error),
22 /// Wraps url parse errors
23 #[error("HTTP URL parse error: {0}")]
24 HttpUrlParseError(#[from] url::ParseError),
25 /// Wraps a bytes-to-utf8 conversion error
26 #[error("String contained invalid bytes: {0}")]
27 StringConversionError(#[from] std::str::Utf8Error),
28 /// Wraps another error type that describes API errors returned by the
29 /// Pandora JSON API
30 #[error("Pandora JSON API error: {0}")]
31 PandoraJsonRequestError(#[from] JsonError),
32 /// Invalid/unsupported audio format was specified
33 #[error("Invalid/unsupported audio format: {0}")]
34 InvalidAudioFormat(String),
35 /// Invalid/unsupported gender string was specified
36 #[error("Invalid/unsupported gender value: {0}")]
37 InvalidUserGender(String),
38}