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