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;
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]
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]
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;
}
}