athena_rs 3.26.3

Hyper performant polyglot Database driver
//! Schema debug-route error mapping helpers.
//!
//! This module centralizes translation of debug-snapshot fetch failures into
//! stable HTTP responses for `/debug/schema` while delegating variant-specific
//! mapping to `debug_errors_snapshot_fetch_variants`.

use actix_web::HttpResponse;

use super::debug_errors_snapshot_fetch_variants::{
    map_snapshot_fetch_columns_error_response, map_snapshot_fetch_relations_error_response,
};
use super::debug_snapshot_error::LoggingSchemaSnapshotError;

/// Maps logging snapshot fetch failures into explicit table/column fetch responses.
pub(super) fn logging_schema_snapshot_fetch_error(err: LoggingSchemaSnapshotError) -> HttpResponse {
    match err {
        LoggingSchemaSnapshotError::FetchRelations(source) => {
            map_snapshot_fetch_relations_error_response(&source)
        }
        LoggingSchemaSnapshotError::FetchColumns(source) => {
            map_snapshot_fetch_columns_error_response(&source)
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::api::schema::debug_snapshot_fetch_error_response_test_helpers::{
        assert_snapshot_fetch_columns_error_response_for_tests,
        assert_snapshot_fetch_relations_error_response_for_tests,
    };

    #[actix_web::test]
    /// Ensures relation snapshot-fetch dispatch preserves the table-fetch payload contract.
    async fn debug_error_dispatch_maps_relations_variant_to_table_fetch_payload() {
        let response =
            logging_schema_snapshot_fetch_error(LoggingSchemaSnapshotError::FetchRelations(
                sqlx::Error::Protocol("relations dispatch failure".to_string()),
            ));

        assert_snapshot_fetch_relations_error_response_for_tests(
            response,
            "relations dispatch failure",
            "debug error dispatch relations",
        )
        .await;
    }

    #[actix_web::test]
    /// Ensures column snapshot-fetch dispatch preserves the column-fetch payload contract.
    async fn debug_error_dispatch_maps_columns_variant_to_column_fetch_payload() {
        let response =
            logging_schema_snapshot_fetch_error(LoggingSchemaSnapshotError::FetchColumns(
                sqlx::Error::Protocol("columns dispatch failure".to_string()),
            ));

        assert_snapshot_fetch_columns_error_response_for_tests(
            response,
            "columns dispatch failure",
            "debug error dispatch columns",
        )
        .await;
    }
}