use actix_web::HttpResponse;
use super::debug_response_mapper_service_error_variants::{
map_fetch_snapshot_service_error_response, map_resolve_logging_client_service_error_response,
};
use super::debug_service_error::LoggingSchemaDebugReportError;
pub(super) fn debug_report_error_response(err: LoggingSchemaDebugReportError) -> HttpResponse {
match err {
LoggingSchemaDebugReportError::ResolveLoggingClient(resp) => {
map_resolve_logging_client_service_error_response(resp)
}
LoggingSchemaDebugReportError::FetchSnapshot(source) => {
map_fetch_snapshot_service_error_response(source)
}
}
}
#[cfg(test)]
mod tests {
use super::super::debug_snapshot_error::LoggingSchemaSnapshotError;
use super::*;
use crate::api::schema::debug_response_test_helpers::{
assert_error_payload_for_tests, response_json_for_tests,
};
#[test]
fn debug_report_error_response_passes_through_client_resolution_status() {
let response =
debug_report_error_response(LoggingSchemaDebugReportError::ResolveLoggingClient(
HttpResponse::ServiceUnavailable().finish(),
));
assert_eq!(
response.status(),
actix_web::http::StatusCode::SERVICE_UNAVAILABLE
);
}
#[actix_web::test]
async fn debug_report_error_response_maps_snapshot_failure_to_internal_error() {
let response = debug_report_error_response(LoggingSchemaDebugReportError::FetchSnapshot(
LoggingSchemaSnapshotError::FetchRelations(sqlx::Error::Protocol(
"snapshot failure".to_string(),
)),
));
assert_eq!(
response.status(),
actix_web::http::StatusCode::INTERNAL_SERVER_ERROR
);
let body = response_json_for_tests(response, "debug-response mapper").await;
assert_error_payload_for_tests(
&body,
"Failed to fetch logging schema tables",
&["Failed to fetch logging schema tables:", "snapshot failure"],
"debug-response mapper",
);
}
}