rspotify_s_model/
error.rs

1use serde::Deserialize;
2use thiserror::Error;
3
4pub type ApiResult<T> = Result<T, ApiError>;
5pub type ModelResult<T> = Result<T, ModelError>;
6
7/// Matches errors that are returned from the Spotfiy
8/// API as part of the JSON response object.
9#[derive(Debug, Error, Deserialize)]
10pub enum ApiError {
11    /// See [Error Object](https://developer.spotify.com/documentation/web-api/reference/#object-errorobject)
12    #[error("{status}: {message}")]
13    #[serde(alias = "error")]
14    Regular { status: u16, message: String },
15
16    /// See [Play Error Object](https://developer.spotify.com/documentation/web-api/reference/#object-playererrorobject)
17    #[error("{status} ({reason}): {message}")]
18    #[serde(alias = "error")]
19    Player {
20        status: u16,
21        message: String,
22        reason: String,
23    },
24}
25
26/// Groups up the kinds of errors that may happen in this crate.
27#[derive(Debug, Error)]
28pub enum ModelError {
29    #[error("json parse error: {0}")]
30    ParseJson(#[from] serde_json::Error),
31
32    #[error("input/output error: {0}")]
33    Io(#[from] std::io::Error),
34}