Skip to content

Commit f4904e7

Browse files
committed
Remove unused API error constructor
1 parent ceee928 commit f4904e7

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

src/models/api/error.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ pub struct ApiError {
1616
pub trace_id: Option<String>,
1717
}
1818

19-
impl ApiError {
20-
/// Creates a new API error.
21-
pub fn new(code: u32, message: impl Into<String>) -> Self {
22-
Self {
23-
code,
24-
err_code: None,
25-
message: message.into(),
26-
errors: None,
27-
trace_id: None,
28-
}
29-
}
30-
}
31-
3219
impl<'de> Deserialize<'de> for ApiError {
3320
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
3421
where

src/models/api/tests.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ fn test_rate_limit() {
1616

1717
#[test]
1818
fn test_api_error() {
19-
let error = ApiError::new(429, "Rate limited");
19+
let error: ApiError = serde_json::from_value(serde_json::json!({
20+
"code": 429,
21+
"message": "Rate limited"
22+
}))
23+
.unwrap();
24+
2025
assert_eq!(error.err_code, None);
2126
assert_eq!(error.code, 429);
27+
assert_eq!(error.message, "Rate limited");
2228

23-
let auth_error = ApiError::new(401, "Unauthorized");
29+
let auth_error: ApiError = serde_json::from_value(serde_json::json!({
30+
"code": 401,
31+
"message": "Unauthorized"
32+
}))
33+
.unwrap();
2434
assert_eq!(auth_error.code, 401);
2535
}
2636

0 commit comments

Comments
 (0)