pdns_client/client/error.rs
1//! The Err type
2
3use serde::Deserialize;
4
5// the #[error("")] is used for generating Display implementations
6// the #[from] <type> is used for From implementations that support converting the error to [`Error`]
7
8/// The error type. This is an enum describing all possible errors returnable.
9/// Unless otherwise specified, assume that a public/exported function returning this enum can return any of its variants.
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12 /// error propagation from the [`reqwest`] crate
13 #[error("HTTP request failed or response JSON parsing errors")]
14 Http(#[from] reqwest::Error),
15
16 /// url parsing error
17 #[error("invalid URL")]
18 Url(#[from] url::ParseError),
19
20 /// invalid api key for [`reqwest::header`]
21 #[error("invalid api key format. could not be inserted into a header")]
22 BadApiKey(#[from] reqwest::header::InvalidHeaderValue),
23
24 /// invalid base url
25 #[error("base url is invalid")]
26 InvalidBaseUrl(String),
27
28 /// error returned by the `PowerDNS` API.
29 #[error(transparent)] // done to forward the display format of [`PdnsAPIError`]
30 APIError(#[from] PdnsAPIError),
31}
32
33// source: <https://doc.powerdns.com/authoritative/http-api/server.html#get--servers-status-codes>
34/// `PowerDNS` API error response.
35#[derive(Debug, Deserialize, thiserror::Error)]
36#[error("{error}: {errors:?}")] // Vec does not implement Display, only Debug and thus we use the debug output of :?
37pub struct PdnsAPIError {
38 /// Summary error.
39 pub error: String,
40
41 /// Individual errors.
42 #[serde(default)]
43 pub errors: Vec<String>,
44}