ic_http_gateway/
error.rs

1//! The error module contains types for common errors that may be thrown
2//! by other modules in this crate.
3
4use ic_agent::AgentError;
5use ic_response_verification::ResponseVerificationError;
6use std::sync::Arc;
7
8/// HTTP gateway result type.
9pub type HttpGatewayResult<T = ()> = Result<T, HttpGatewayError>;
10
11/// HTTP gateway error type.
12#[derive(thiserror::Error, Debug, Clone)]
13pub enum HttpGatewayError {
14    #[error(transparent)]
15    ResponseVerificationError(#[from] ResponseVerificationError),
16
17    /// Inner error from agent.
18    #[error(transparent)]
19    AgentError(#[from] Arc<AgentError>),
20
21    /// HTTP error.
22    #[error(transparent)]
23    HttpError(#[from] Arc<http::Error>),
24
25    #[error(r#"Failed to parse the "{header_name}" header value: "{header_value:?}""#)]
26    HeaderValueParsingError {
27        header_name: String,
28        header_value: String,
29    },
30}
31
32impl From<AgentError> for HttpGatewayError {
33    fn from(err: AgentError) -> Self {
34        HttpGatewayError::AgentError(Arc::new(err))
35    }
36}
37
38impl From<http::Error> for HttpGatewayError {
39    fn from(err: http::Error) -> Self {
40        HttpGatewayError::HttpError(Arc::new(err))
41    }
42}