Skip to content

Commit

Permalink
feat(ic-http-gateway): propagate http error
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanosdev committed Dec 12, 2024
1 parent 192559e commit e8ceded
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions packages/ic-http-gateway/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! The error module contains types for common errors that may be thrown
//! by other modules in this crate.
use ic_agent::AgentError;
use ic_response_verification::ResponseVerificationError;
use std::sync::Arc;

/// HTTP gateway result type.
Expand All @@ -10,15 +12,15 @@ pub type HttpGatewayResult<T = ()> = Result<T, HttpGatewayError>;
#[derive(thiserror::Error, Debug, Clone)]
pub enum HttpGatewayError {
#[error(transparent)]
ResponseVerificationError(#[from] ic_response_verification::ResponseVerificationError),
ResponseVerificationError(#[from] ResponseVerificationError),

/// Inner error from agent.
#[error(transparent)]
AgentError(#[from] Arc<ic_agent::AgentError>),
AgentError(#[from] Arc<AgentError>),

/// HTTP error.
#[error(r#"HTTP error: "{0}""#)]
HttpError(String),
#[error(transparent)]
HttpError(#[from] Arc<http::Error>),

#[error(r#"Failed to parse the "{header_name}" header value: "{header_value:?}""#)]
HeaderValueParsingError {
Expand All @@ -27,20 +29,14 @@ pub enum HttpGatewayError {
},
}

impl From<ic_agent::AgentError> for HttpGatewayError {
fn from(err: ic_agent::AgentError) -> Self {
impl From<AgentError> for HttpGatewayError {
fn from(err: AgentError) -> Self {
HttpGatewayError::AgentError(Arc::new(err))
}
}

impl From<http::Error> for HttpGatewayError {
fn from(err: http::Error) -> Self {
HttpGatewayError::HttpError(err.to_string())
}
}

impl From<http::status::InvalidStatusCode> for HttpGatewayError {
fn from(err: http::status::InvalidStatusCode) -> Self {
HttpGatewayError::HttpError(err.to_string())
HttpGatewayError::HttpError(Arc::new(err))
}
}
2 changes: 1 addition & 1 deletion packages/ic-http-gateway/src/protocol/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub async fn process_request(
metadata: HttpGatewayResponseMetadata {
upgraded_to_update_call: is_update_call,
response_verification_version,
internal_error: Some(e.into()),
internal_error: Some(http::Error::from(e).into()),
},
}
}
Expand Down

0 comments on commit e8ceded

Please sign in to comment.