Skip to content

Commit 758b169

Browse files
committed
fixup! Fix exit code on tedge cert error
1 parent ec2bf68 commit 758b169

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

crates/core/c8y_api/src/http_proxy.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,19 @@ impl C8yEndPoint {
6969
c8y_profile: Option<&str>,
7070
) -> Result<Self, C8yEndPointConfigError> {
7171
let c8y_config = tedge_config.c8y.try_get(c8y_profile)?;
72-
let c8y_host = c8y_config.proxy.client.host.to_string();
73-
let c8y_mqtt_host = c8y_host.clone();
7472
let auth_proxy_addr = c8y_config.proxy.client.host.clone();
7573
let auth_proxy_port = c8y_config.proxy.client.port;
7674
let auth_proxy_protocol = c8y_config
7775
.proxy
7876
.cert_path
7977
.or_none()
8078
.map_or(Protocol::Http, |_| Protocol::Https);
79+
let c8y_host = format!(
80+
"{}://{auth_proxy_addr}:{auth_proxy_port}",
81+
auth_proxy_protocol.as_str()
82+
);
83+
let c8y_mqtt_host = c8y_host.clone();
8184
let proxy = ProxyUrlGenerator::new(auth_proxy_addr, auth_proxy_port, auth_proxy_protocol);
82-
8385
Ok(C8yEndPoint {
8486
c8y_host,
8587
c8y_mqtt_host,

crates/core/tedge/src/cli/certificate/c8y/renew.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ pub struct RenewCertCmd {
4747
#[async_trait::async_trait]
4848
impl Command for RenewCertCmd {
4949
fn description(&self) -> String {
50-
format!("renew the device certificate from {}", self.c8y_url())
50+
format!(
51+
"renew the device certificate via Cumulocity HTTP proxy {}",
52+
self.c8y_url()
53+
)
5154
}
5255

5356
async fn execute(&self) -> Result<(), MaybeFancy<Error>> {
@@ -103,10 +106,8 @@ impl RenewCertCmd {
103106
response.status(),
104107
response.text().await.unwrap_or("".to_string())
105108
)),
106-
Err(err) => Err(anyhow!(
107-
"Fail to connect to {url}: {:?}",
108-
get_webpki_error_from_reqwest(err)
109-
)),
109+
Err(err) => Err(Error::new(get_webpki_error_from_reqwest(err))
110+
.context(format!("Fail to connect to Cumulocity HTTP proxy {url}"))),
110111
}
111112
}
112113

crates/core/tedge/src/cli/certificate/error.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ pub enum CertError {
7979
#[error(transparent)]
8080
PathsError(#[from] PathsError),
8181

82+
#[error("Connection error: {0}")]
83+
ReqwestConnect(String),
84+
85+
#[error("Request time out")]
86+
ReqwestTimeout,
87+
8288
#[error(transparent)]
8389
ReqwestError(#[from] reqwest::Error),
8490

@@ -161,6 +167,16 @@ pub fn get_webpki_error_from_reqwest(err: reqwest::Error) -> CertError {
161167
{
162168
CertError::CertificateError(tls_error)
163169
} else {
164-
CertError::ReqwestError(err) // any other Error type than `hyper::Error`
170+
// any other Error type than `hyper::Error`
171+
if err.is_connect() {
172+
match err.source().and_then(|err| err.source()) {
173+
Some(io_error) => CertError::ReqwestConnect(format!("{io_error}")),
174+
None => CertError::ReqwestError(err),
175+
}
176+
} else if err.is_timeout() {
177+
CertError::ReqwestTimeout
178+
} else {
179+
CertError::ReqwestError(err)
180+
}
165181
}
166182
}

0 commit comments

Comments
 (0)