attackerkb_api_rs/
error.rs1use serde::{Deserialize, Serialize};
4use std::fmt::{Display, Formatter};
5
6#[derive(Debug, thiserror::Error)]
8pub enum Error {
9 #[error("Invalid AttackerKB API Token: {}", source)]
10 InvalidApiToken {
11 source: reqwest::header::InvalidHeaderValue,
12 },
13
14 #[error("Unable to build reqwest HTTP client: {}", source)]
15 BuildingClient { source: reqwest::Error },
16
17 #[error("Error sending HTTP request: {}", source)]
18 RequestFailed {
19 #[from]
20 source: reqwest::Error,
21 },
22 #[error("Error reading response: {}", source)]
23 ResponseIo { source: reqwest::Error },
24
25 #[error("API Error ({}): {}", .error.status, .error.message)]
26 Api { error: ErrorResponse },
27}
28
29#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Hash)]
30#[serde(untagged)]
31pub enum StatusCode {
32 NonZeroU16(u16),
33 String(String),
34}
35
36impl Display for StatusCode {
37 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
38 let v = match self {
39 StatusCode::NonZeroU16(n) => n.to_string(),
40 StatusCode::String(s) => s.to_string(),
41 };
42 write!(f, "{}", v)
43 }
44}
45
46#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
48pub struct ErrorResponse {
49 pub message: String,
52 pub status: StatusCode,
55}