7 files changed
+22
-22
Cargo.lock
+1
@@ -1693,6 +1693,7 @@ dependencies = [
1693
"spinners",
1694
"strum 0.27.1",
1695
"strum_macros 0.27.1",
1696
+ "thiserror 2.0.12",
1697
]
1698
1699
[[package]]
crates/cli/src/project/deployment.rs
-4
@@ -52,8 +52,6 @@ struct DeploymentRow {
52
id: i32,
53
commit_hash: String,
54
status: String,
55
- created_at: String,
56
- updated_at: String,
55
}
56
57
pub fn show_project_deployments(deployments: &[Deployment]) {
@@ -63,8 +61,6 @@ pub fn show_project_deployments(deployments: &[Deployment]) {
61
id: d.id,
62
commit_hash: d.commit_hash.clone(),
63
status: format!("{:?}", d.status),
66
- created_at: d.created_at.format("%Y-%m-%d %H:%M:%S").to_string(),
67
- updated_at: d.updated_at.format("%Y-%m-%d %H:%M:%S").to_string(),
64
})
65
.collect();
66
crates/smbcloud-model/Cargo.toml
+1
@@ -25,3 +25,4 @@ serde_repr = { workspace = true }
25
spinners = { workspace = true }
26
strum = { workspace = true }
27
strum_macros = { workspace = true }
28
+thiserror = { workspace = true }
crates/smbcloud-model/src/error_codes.rs
+8
-8
@@ -7,6 +7,7 @@ use std::{
7
use serde::{Deserialize, Serialize};
8
use serde_repr::{Deserialize_repr, Serialize_repr};
9
use strum_macros::EnumIter;
10
+use thiserror::Error;
11
12
#[derive(Serialize, Deserialize, Debug)]
13
#[serde(untagged)]
@@ -25,22 +26,20 @@ impl Display for ErrorResponse {
26
}
27
}
28
28
-#[derive(Serialize_repr, Deserialize_repr, Debug, EnumIter)]
29
+#[derive(Error, Serialize_repr, Deserialize_repr, Debug, EnumIter)]
30
#[repr(i32)]
31
pub enum ErrorCode {
31
- Unknown = 0,
32
+ #[error("Unknown error.")]
33
+ Unknown = 0,
34
+ #[error("Parse error.")]
35
ParseError = 1,
36
+ #[error("Network error.")]
37
NetworkError = 2,
38
// Projects
39
+ #[error("Project not found.")]
40
ProjectNotFound = 1000
41
}
42
38
-impl Display for ErrorCode {
39
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
40
- write!(f, "{:?}", self)
41
- }
42
-}
43
-
43
impl ErrorCode {
44
/// Cannot expose the ErrorCode enum directly to Ruby,
45
/// so we need to get it from i32.
@@ -55,6 +54,7 @@ impl ErrorCode {
54
}
55
}
56
57
+ // This could be better.
58
pub fn message(&self, l: Option<String>) -> &str {
59
print!("Language code: {:?}, {}", l, self);
60
match self {
crates/smbcloud-model/src/project.rs
+1
-1
@@ -11,7 +11,7 @@ pub struct Config {
11
pub current_auth_app: Option<AuthApp>,
12
}
13
14
-#[derive(Deserialize, Debug, Serialize, Clone)]
14
+#[derive(Deserialize, Serialize, Debug, Clone)]
15
pub struct Project {
16
pub id: i32,
17
pub name: String,
crates/smbcloud-networking-project/src/crud_project_deployment_read.rs
+2
-3
@@ -47,10 +47,9 @@ pub async fn get_project(
47
access_token: String,
48
id: String
49
) -> Result<Project, ErrorResponse> {
50
- let builder = Client::new()
50
+ let builder: reqwest::RequestBuilder = Client::new()
51
.get(build_project_url_with_id(env, id))
52
.header("Authorization", access_token)
53
.header("User-agent", SMB_USER_AGENT);
54
-
55
- request(builder).await?
54
+ request(builder).await
55
}
\ No newline at end of file
crates/smbcloud-networking/src/network.rs
+9
-6
@@ -1,10 +1,9 @@
1
-
2
-use log::{debug, error};
1
+use log::error;
2
use reqwest::{RequestBuilder, Response};
3
use serde::de::DeserializeOwned;
4
use smbcloud_model::error_codes::{ErrorCode, ErrorResponse};
5
#[cfg(debug_assertions)]
7
-const LOG_RESPONSE_BODY: bool = true; // You know what to do here.
6
+const LOG_RESPONSE_BODY: bool = false; // You know what to do here.
7
#[cfg(not(debug_assertions))]
8
const LOG_RESPONSE_BODY: bool = false;
9
@@ -23,9 +22,11 @@ pub async fn parse_error_response<T: DeserializeOwned>(
22
};
23
24
if LOG_RESPONSE_BODY {
25
+ println!("Parse Error >>>>");
26
println!("{:?}", serde_json::to_string_pretty(&response_body));
27
+ println!("Parse Error >>>>");
28
}
28
-
29
+
30
let e = match serde_json::from_str::<ErrorResponse>(&response_body) {
31
Ok(json) => json,
32
Err(e) => {
@@ -72,7 +73,9 @@ pub async fn request<R: DeserializeOwned>(builder: RequestBuilder) -> Result<R,
73
};
74
75
if LOG_RESPONSE_BODY {
75
- debug!("{:?}", serde_json::to_string_pretty(&response_body));
76
+ println!("Parse >>>>");
77
+ println!("{:?}", serde_json::to_string_pretty(&response_body));
78
+ println!("Parse >>>>");
79
}
80
81
let response = match serde_json::from_str::<R>(&response_body) {
@@ -87,4 +90,4 @@ pub async fn request<R: DeserializeOwned>(builder: RequestBuilder) -> Result<R,
90
};
91
92
Ok(response)
90
-}
\ No newline at end of file
93
+}