Skip to content

Commit aa5e33b

Browse files
authored
feat(ic-http-gateway): propagate http error (#33)
1 parent a0b3b4f commit aa5e33b

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! The error module contains types for common errors that may be thrown
22
//! by other modules in this crate.
33
4+
use ic_agent::AgentError;
5+
use ic_response_verification::ResponseVerificationError;
46
use std::sync::Arc;
57

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

1517
/// Inner error from agent.
1618
#[error(transparent)]
17-
AgentError(#[from] Arc<ic_agent::AgentError>),
19+
AgentError(#[from] Arc<AgentError>),
1820

1921
/// HTTP error.
20-
#[error(r#"HTTP error: "{0}""#)]
21-
HttpError(String),
22+
#[error(transparent)]
23+
HttpError(#[from] Arc<http::Error>),
2224

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

30-
impl From<ic_agent::AgentError> for HttpGatewayError {
31-
fn from(err: ic_agent::AgentError) -> Self {
32+
impl From<AgentError> for HttpGatewayError {
33+
fn from(err: AgentError) -> Self {
3234
HttpGatewayError::AgentError(Arc::new(err))
3335
}
3436
}
3537

3638
impl From<http::Error> for HttpGatewayError {
3739
fn from(err: http::Error) -> Self {
38-
HttpGatewayError::HttpError(err.to_string())
39-
}
40-
}
41-
42-
impl From<http::status::InvalidStatusCode> for HttpGatewayError {
43-
fn from(err: http::status::InvalidStatusCode) -> Self {
44-
HttpGatewayError::HttpError(err.to_string())
40+
HttpGatewayError::HttpError(Arc::new(err))
4541
}
4642
}

packages/ic-http-gateway/src/protocol/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub async fn process_request(
202202
metadata: HttpGatewayResponseMetadata {
203203
upgraded_to_update_call: is_update_call,
204204
response_verification_version: None,
205-
internal_error: Some(e.into()),
205+
internal_error: Some(http::Error::from(e).into()),
206206
},
207207
};
208208
}
@@ -263,7 +263,7 @@ pub async fn process_request(
263263
metadata: HttpGatewayResponseMetadata {
264264
upgraded_to_update_call: is_update_call,
265265
response_verification_version,
266-
internal_error: Some(e.into()),
266+
internal_error: Some(http::Error::from(e).into()),
267267
},
268268
}
269269
}

0 commit comments

Comments
 (0)