batch_mode_batch_triple/
log_errors.rs

1// ---------------- [ File: batch-mode-batch-triple/src/log_errors.rs ]
2crate::ix!();
3
4impl BatchFileTriple {
5
6    pub async fn log_errors(&self, error_data: &BatchErrorData) 
7        -> Result<(), BatchErrorProcessingError> 
8    {
9        info!("logging possible errors in our BatchErrorData of len {}", error_data.len());
10
11        for response_record in error_data.responses() {
12            if let BatchResponseBody::Error(error_body) = response_record.response().body() {
13                let message = error_body.error().message();
14                let custom_id = response_record.custom_id().as_str();
15                println!("Error in request {}: {}", custom_id, message);
16                // Replace with proper logging
17            }
18        }
19        Ok(())
20    }
21}
22
23#[cfg(test)]
24mod batch_file_triple_log_errors_exhaustive_tests {
25    use super::*;
26    use serde_json::json;
27
28    #[traced_test]
29    async fn log_errors_handles_empty_error_data_gracefully() {
30        trace!("===== BEGIN TEST: log_errors_handles_empty_error_data_gracefully =====");
31
32        // Arrange
33        let triple = make_mock_batch_file_triple();
34        let empty_error_data = BatchErrorData::new(vec![]);
35
36        // Act
37        let res = triple.log_errors(&empty_error_data).await;
38        debug!("Result of log_errors call on empty data: {:?}", res);
39
40        // Assert
41        assert!(res.is_ok(), "log_errors should succeed even with empty error data");
42
43        trace!("===== END TEST: log_errors_handles_empty_error_data_gracefully =====");
44    }
45
46    #[traced_test]
47    async fn log_errors_detects_and_logs_error_bodies() {
48        trace!("===== BEGIN TEST: log_errors_detects_and_logs_error_bodies =====");
49
50        // Arrange
51        let triple = make_mock_batch_file_triple();
52
53        // We explicitly create a 400 error record with "Some error message"
54        let error_response = BatchResponseRecord::mock_with_code_and_body(
55            "test_failing_item",
56            400,
57            &json!({
58                "error": {
59                    "message": "Some error message",
60                    "type": "test_error",
61                    "param": null,
62                    "code": null
63                }
64            }),
65        );
66        let error_data = BatchErrorData::new(vec![error_response]);
67
68        // Act
69        let res = triple.log_errors(&error_data).await;
70        debug!("Result of log_errors call on single error: {:?}", res);
71
72        // We expect it to succeed but also to log the error lines.
73        assert!(res.is_ok(), "log_errors should succeed with valid error data");
74
75        trace!("===== END TEST: log_errors_detects_and_logs_error_bodies =====");
76    }
77}