1use std::fmt;
3
4use reqwest::header::InvalidHeaderValue;
5use serde::{Deserialize, Serialize};
6use thiserror::Error;
7
8#[derive(Error, Debug)]
9pub enum HypothesisError {
10 #[error("Make sure input fields are valid")]
11 APIError {
12 #[source]
13 source: APIError,
14 serde_error: Option<serde_json::Error>,
15 raw_text: String,
16 },
17 #[error("Invalid header value")]
18 HeaderError(#[from] InvalidHeaderValue),
19 #[error("Reqwest error")]
20 ReqwestError(#[from] reqwest::Error),
21 #[error("{suggestion:?}")]
22 EnvironmentError {
23 #[source]
24 source: std::env::VarError,
25 suggestion: String,
26 },
27 #[error("JSON format error")]
28 SerdeError(#[from] serde_json::Error),
29 #[error("Couldn't parse URL")]
30 URLError(#[from] url::ParseError),
31 #[error("Builder error: {0}")]
32 BuilderError(String),
33}
34
35#[derive(Error, Serialize, Deserialize, Debug, Default, Clone)]
37pub struct APIError {
38 pub status: String,
40 pub reason: String,
42}
43
44impl fmt::Display for APIError {
45 #[inline]
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 write!(f, "Status: {}\nReason: {}", self.status, self.reason)
48 }
49}
50
51#[cfg(feature = "cli")]
52#[derive(Error, Serialize, Deserialize, Debug, Clone)]
54pub enum CLIError {
55 #[error("Could not authorize")]
57 AuthorizationError,
58 #[error("ParseError: {name:?} must be one of {types:?}")]
60 ParseError { name: String, types: Vec<String> },
61}