sponsor_block/
error.rs

1//! Everything associated with library errors.
2
3// Uses
4use std::result;
5
6use thiserror::Error;
7
8/// The library error type.
9#[derive(Error, Debug)]
10pub enum SponsorBlockError {
11	// HTTP-Related Error Types
12	/// An internal server error with the API.
13	///
14	/// Contains the status code returned by the server.
15	#[error("internal API error, with status code {0}")]
16	HttpApi(StatusCode),
17	/// A client-side error during communication with the API. A value of 404
18	/// simply means no segments could be found in the database for the video ID
19	/// you requested.
20	///
21	/// If encountering this, it's possible the library version you're using is
22	/// out of date with the API. If that's the case, please open an issue.
23	///
24	/// Contains the status code returned by the server.
25	#[error("client HTTP error, with status code {0}")]
26	HttpClient(StatusCode),
27	/// An unknown error during communication with the API.
28	///
29	/// Contains the status code returned by the server.
30	#[error("unknown HTTP error, with status code {0}")]
31	HttpUnknown(StatusCode),
32	/// An actual communication error. Likely a network or protocol issue.
33	/// Contains the internal [`reqwest::Error`].
34	#[error("unable to communicate with the API")]
35	HttpCommunication(#[from] reqwest::Error),
36
37	// Other API Errors
38	/// The API does not have any segments in the database for the requested
39	/// video ID.
40	///
41	/// This should effectively be treated the same way as an
42	/// [`HttpClient(404)`].
43	///
44	/// [`HttpClient(404)`]: crate::SponsorBlockError::HttpClient
45	#[cfg(feature = "private_searches")]
46	#[error("unable to find a matching hash for the provided video ID")]
47	NoMatchingVideoHash,
48
49	// Serialization
50	/// An error encountered when deserializing JSON data received from the API.
51	///
52	/// If encountering this, it's likely the library version you're using is
53	/// out of date with the API. If that's the case, please open an issue.
54	///
55	/// Contains the internal [`serde_json::Error`].
56	#[error("unable to deserialize data from the API")]
57	Deserialization(#[from] serde_json::Error),
58
59	// Data Verification
60	/// Data received from the API does not make sense or fails to meet sanity
61	/// requirements.
62	#[error("data received from the API does not meet verification: {0}")]
63	BadData(String),
64}
65
66/// An HTTP status code number.
67pub type StatusCode = u16;
68
69/// A convenience type for the return result of service calls.
70pub type Result<T> = result::Result<T, SponsorBlockError>;