athena_rs 3.23.0

Hyper performant polyglot Database driver
Documentation
//! Snapshot-fetch variant error mapping for `/debug/schema`.
//!
//! This module maps relation/column snapshot fetch SQL errors into stable,
//! route-ready HTTP responses.

use actix_web::HttpResponse;

use super::catalog_errors::schema_internal_fetch_error;

/// Maps relation snapshot-fetch SQL errors into route-ready HTTP responses.
pub(super) fn map_snapshot_fetch_relations_error_response(err: &sqlx::Error) -> HttpResponse {
    schema_internal_fetch_error("logging schema tables", err)
}

/// Maps column snapshot-fetch SQL errors into route-ready HTTP responses.
pub(super) fn map_snapshot_fetch_columns_error_response(err: &sqlx::Error) -> HttpResponse {
    schema_internal_fetch_error("logging schema columns", err)
}

#[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 SQL failures map to the stable 500 error envelope.
    async fn variant_mapper_maps_relations_fetch_error_to_internal_error() {
        let response = map_snapshot_fetch_relations_error_response(&sqlx::Error::Protocol(
            "relations failed".to_string(),
        ));

        assert_snapshot_fetch_relations_error_response_for_tests(
            response,
            "relations failed",
            "snapshot fetch variant mapper relations",
        )
        .await;
    }

    #[actix_web::test]
    /// Ensures column snapshot-fetch SQL failures map to the stable 500 error envelope.
    async fn variant_mapper_maps_columns_fetch_error_to_internal_error() {
        let response = map_snapshot_fetch_columns_error_response(&sqlx::Error::Protocol(
            "columns failed".to_string(),
        ));

        assert_snapshot_fetch_columns_error_response_for_tests(
            response,
            "columns failed",
            "snapshot fetch variant mapper columns",
        )
        .await;
    }
}