use reqwest::Client;
use std::time::Duration;
use crate::GraphError;
pub(crate) fn http_client() -> Client {
Client::builder()
.timeout(Duration::from_secs(30))
.connect_timeout(Duration::from_secs(5))
.build()
.unwrap_or_else(|_| Client::new())
}
pub(crate) fn conn_err(e: reqwest::Error) -> GraphError {
GraphError::ConnectionError(e.to_string())
}
pub(crate) fn query_err(e: reqwest::Error) -> GraphError {
GraphError::QueryError(e.to_string())
}
pub(crate) async fn http_error(res: reqwest::Response, backend: &str, op: &str) -> GraphError {
let status = res.status();
let body = res.text().await.unwrap_or_default();
GraphError::QueryError(format!("{backend} {op} failed with {status}: {body}"))
}
#[cfg(any(feature = "neo4j", feature = "nebulagraph"))]
pub(crate) fn backtick(s: &str) -> String {
s.replace('`', "``")
}
#[cfg(any(feature = "nebulagraph", feature = "arangodb"))]
pub(crate) fn esc(s: &str) -> String {
s.replace('\\', "\\\\").replace('"', "\\\"")
}