Skip to main content

aep_agent/
error.rs

1use aep_core::{AgentStatus, ClaimName, ProblemDetails};
2use thiserror::Error;
3
4use crate::PlatformPendingSign;
5
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub enum InspectErrorCode {
8    HttpError,
9    InvalidJson,
10    InvalidMediaType,
11    InvalidRedirect,
12    ResponseTooLarge,
13    ServiceIdentityMismatch,
14    ValidationFailed,
15}
16
17#[derive(Debug, Error)]
18pub enum AgentError {
19    #[error("{0}")]
20    InvalidConfiguration(String),
21    #[error("{0}")]
22    InvalidServiceReference(String),
23    #[error("AEP Inspect failed: {message}")]
24    Inspect {
25        code: InspectErrorCode,
26        message: String,
27        status: Option<u16>,
28    },
29    #[error("AEP Service does not advertise {0}")]
30    CommandNotAdvertised(String),
31    #[error("AEP command failed with HTTP {status}")]
32    Command {
33        status: u16,
34        problem: Option<Box<ProblemDetails>>,
35    },
36    #[error("AEP Agent cannot satisfy the Service's required Claim Names: {names}")]
37    ClaimRequirements {
38        missing: Vec<ClaimName>,
39        names: String,
40    },
41    #[error("AEP Agent identity did not become active: {}", status.as_str())]
42    EnrollmentState { status: AgentStatus },
43    #[error("AEP Status polling timed out")]
44    PollingTimeout,
45    #[error("AEP Platform signing is pending")]
46    PlatformSignPending { pending: Box<PlatformPendingSign> },
47    #[error("AEP Platform command failed with HTTP {status}")]
48    PlatformCommand {
49        status: u16,
50        problem: Option<Box<ProblemDetails>>,
51    },
52    #[error("AEP Service does not advertise a compatible grant type")]
53    NoCompatibleGrantType,
54    #[error("AEP Service does not advertise a compatible protected-resource authentication method")]
55    NoAuthenticationMethod,
56    #[error("{0}")]
57    Identity(String),
58    #[error("{0}")]
59    Credential(String),
60    #[error("{0}")]
61    Store(String),
62    #[error("{0}")]
63    Transport(String),
64    #[error(transparent)]
65    Core(#[from] aep_core::CoreError),
66    #[error(transparent)]
67    Parse(#[from] aep_core::ParseError),
68    #[error(transparent)]
69    Json(#[from] serde_json::Error),
70    #[error(transparent)]
71    Url(#[from] url::ParseError),
72}
73
74impl AgentError {
75    pub(crate) fn claims(missing: Vec<ClaimName>) -> Self {
76        let names = missing
77            .iter()
78            .map(ClaimName::as_str)
79            .collect::<Vec<_>>()
80            .join(", ");
81        Self::ClaimRequirements { missing, names }
82    }
83}