bugbite/
error.rs

1use std::io;
2
3#[cfg(feature = "python")]
4pub mod python;
5
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    #[error("authentication required")]
9    Auth,
10    #[error("{0}")]
11    Config(String),
12    #[error("no parameters specified")]
13    EmptyParams,
14    #[error("invalid URL: {0}")]
15    InvalidUrl(url::ParseError),
16    #[error("{0}")]
17    InvalidRequest(String),
18    #[error("invalid service response: {0}")]
19    InvalidResponse(String),
20    #[error("{0}")]
21    InvalidValue(String),
22    #[error("{0}")]
23    IO(String),
24    #[error("bugzilla: {message}")]
25    Bugzilla { code: i64, message: String },
26    #[error("redmine: {0}")]
27    Redmine(String),
28    #[error("{0}")]
29    Request(reqwest::Error),
30    #[error("request timed out")]
31    Timeout,
32}
33
34impl From<reqwest::Error> for Error {
35    fn from(e: reqwest::Error) -> Self {
36        if e.is_timeout() {
37            Error::Timeout
38        } else {
39            // drop URL from error to avoid potentially leaking authentication parameters
40            Error::Request(e.without_url())
41        }
42    }
43}
44
45impl From<io::Error> for Error {
46    fn from(e: io::Error) -> Self {
47        Error::IO(format!("{e}: {}", e.kind()))
48    }
49}
50
51impl From<url::ParseError> for Error {
52    fn from(e: url::ParseError) -> Self {
53        Error::InvalidUrl(e)
54    }
55}