const PG_SQLSTATE_QUERY_CANCELED: &str = "57014";
#[derive(Debug, thiserror::Error)]
pub enum SqlColdError {
#[error("postgres statement_timeout exceeded")]
Timeout,
#[error("sqlx error: {0}")]
Sqlx(sqlx::Error),
#[error("conversion error: {0}")]
Convert(String),
}
impl From<sqlx::Error> for SqlColdError {
fn from(e: sqlx::Error) -> Self {
if let sqlx::Error::Database(ref db) = e
&& db.code().as_deref() == Some(PG_SQLSTATE_QUERY_CANCELED)
{
return Self::Timeout;
}
Self::Sqlx(e)
}
}
impl From<SqlColdError> for signet_cold::ColdStorageError {
fn from(error: SqlColdError) -> Self {
match error {
SqlColdError::Timeout => Self::DeadlineExceeded(std::time::Duration::ZERO),
other => Self::Backend(Box::new(other)),
}
}
}