Skip to main content

commit_bridge/trigger/
error.rs

1//! Error type definitions.
2
3use thiserror::Error;
4
5/// An error that interrupted a workflow trigger loop iteration.
6#[derive(Debug, Error)]
7pub enum WorkflowTriggerError {
8    /// Error during JWT or IAT authentication.
9    #[error("Authentication error: {0}")]
10    Auth(#[from] AuthError),
11
12    /// Database error.
13    #[error("Database error: {0}")]
14    Database(#[from] sqlx::Error),
15
16    /// Repository error.
17    #[error("Repository error: {0}")]
18    Repository(#[from] crate::repository::RepositoryError),
19
20    /// API service error.
21    #[error(transparent)]
22    Api(#[from] RequestError),
23}
24
25impl From<reqwest::Error> for WorkflowTriggerError {
26    fn from(e: reqwest::Error) -> Self {
27        Self::Api(RequestError::Request(e))
28    }
29}
30
31/// Authentication errors.
32#[derive(Debug, Error)]
33pub enum AuthError {
34    /// Failed to read PEM file.
35    #[error("Could not read PEM file: {0}")]
36    PemFile(#[from] std::io::Error),
37
38    /// An error with time APIs.
39    #[error("System time: {0}")]
40    Time(#[from] std::time::SystemTimeError),
41
42    /// Error while generating a JWT.
43    #[error("JWT generation failed: {0}")]
44    Jwt(#[from] jsonwebtoken::errors::Error),
45
46    /// Authentication server error.
47    #[error(transparent)]
48    Server(#[from] RequestError),
49}
50
51impl From<reqwest::Error> for AuthError {
52    fn from(e: reqwest::Error) -> Self {
53        Self::Server(RequestError::Request(e))
54    }
55}
56
57/// An error while performing an HTTP request.
58#[derive(Debug, Error)]
59pub enum RequestError {
60    /// Missing response from API service.
61    #[error("HTTP request failed: {0}")]
62    Request(#[from] reqwest::Error),
63
64    /// Bad response from API service.
65    #[error("Unexpected HTTP response ({status}): {text}")]
66    Response {
67        /// The HTTP status code of the response.
68        status: reqwest::StatusCode,
69        /// The full text of the HTTP response.
70        text: String,
71    },
72}