Skip to content

Commit cb4967b

Browse files
committed
Fix: error_code type using curl_sys properly
1 parent 53bf45f commit cb4967b

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src-tauri/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ url = "2.5.4"
2828
uuid = { version = "1.11.0", features = ["v4", "fast-rng"] }
2929
tauri-plugin-process = "2"
3030
tauri-plugin-fs = "2"
31+
curl-sys = "0.4.78"
3132

3233
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
3334
tauri-plugin-global-shortcut = "2"

src-tauri/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ struct HTTPAPIResponse {
4444

4545
#[derive(serde::Serialize)]
4646
struct HTTPAPIErrorResponse {
47-
error_code: i32,
47+
// TODO: should have an error type to help distungish between curl native errors and custom app logic errors
48+
// error_code: Option<u32>,
49+
error_code: Option<curl_sys::CURLcode>,
4850
error_message: String,
4951
}
5052

@@ -66,7 +68,7 @@ fn http_request(
6668
// println!("{}, {}", url, url_encode);
6769

6870
let mut error_str: String = "".to_string();
69-
let mut error_code: i32 = -1;
71+
let mut error_code: Option<curl_sys::CURLcode> = None;
7072

7173
match easy.url(
7274
// Setting - OFF
@@ -79,7 +81,7 @@ fn http_request(
7981
Err(e) => {
8082
return Err(HTTPAPIErrorResponse {
8183
error_code: error_code,
82-
error_message: format!("Test - {}", e.to_string()),
84+
error_message: format!("{}", e.to_string()),
8385
})
8486
}
8587
}
@@ -228,7 +230,7 @@ fn http_request(
228230
Err(e) => {
229231
return Err(HTTPAPIErrorResponse {
230232
error_code: error_code,
231-
error_message: format!("Test - {}", e.to_string()),
233+
error_message: format!("{}", e.to_string()),
232234
})
233235
}
234236
};
@@ -349,7 +351,7 @@ fn http_request(
349351
println!("Request failed: {}", err);
350352

351353
return Err(HTTPAPIErrorResponse {
352-
error_code: err.code(),
354+
error_code: Some(err.code()),
353355
error_message: err.to_string(),
354356
});
355357
}

0 commit comments

Comments
 (0)