rspotify_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    Regular { status: u16, message: String },
14
15    /// See [Play Error Object](https://developer.spotify.com/documentation/web-api/reference/#object-playererrorobject)
16    #[error("{status} ({reason}): {message}")]
17    Player {
18        status: u16,
19        message: String,
20        reason: String,
21    },
22}
23
24/// Groups up the kinds of errors that may happen in this crate.
25#[derive(Debug, Error)]
26pub enum ModelError {
27    #[error("json parse error: {0}")]
28    ParseJson(#[from] serde_json::Error),
29
30    #[error("input/output error: {0}")]
31    Io(#[from] std::io::Error),
32}