batch_mode_batch_schema/
batch_error_response_body.rs1crate::ix!();
3
4#[derive(Debug,Serialize,Deserialize)]
5pub struct BatchErrorResponseBody {
6 error: BatchErrorDetails,
7}
8
9impl BatchErrorResponseBody {
10 pub fn error(&self) -> &BatchErrorDetails {
11 &self.error
12 }
13}
14
15#[cfg(test)]
16mod tests {
17 use super::*;
18 use serde_json::json;
19
20 #[test]
21 fn test_error_body_deserialization() {
22 let json_data = json!({
23 "error": {
24 "message": "Invalid API key",
25 "type": "authentication_error",
26 "param": null,
27 "code": "invalid_api_key"
28 }
29 });
30
31 let body: BatchErrorResponseBody = serde_json::from_value(json_data).unwrap();
32 assert_eq!(body.error().message(), "Invalid API key");
33 assert_eq!(body.error().error_type(), "authentication_error");
34 assert_eq!(body.error().code(), Some("invalid_api_key"));
35 }
36
37 #[test]
38 fn test_error_body_missing_fields() {
39 let json_data = json!({
40 "error": {
41 "message": "An error occurred"
42 }
44 });
45
46 let result: Result<BatchErrorResponseBody, _> = serde_json::from_value(json_data);
47 assert!(result.is_err(), "Deserialization should fail if required fields are missing");
48 }
49}