use std::num::TryFromIntError;
use bonsaidb::core::{pubsub, Error as BonsaiError};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("Error interacting with BonsaiDB: {0}")]
BonsaiDb(#[from] BonsaiError),
#[error("PubSub was disconnected: {0}")]
PubSubDisconnected(#[from] pubsub::Disconnected),
#[error("Getrandom error: {0}")]
Getrandom(#[from] getrandom::Error),
#[error("Integer conversion error: {0}")]
TryFromInt(#[from] TryFromIntError),
#[error("Serde JSON (de-)serialization failed: {0}")]
SerdeJson(#[from] serde_json::Error),
}
impl Error {
#[must_use]
pub fn should_retry(&self) -> bool {
#[allow(clippy::match_like_matches_macro)]
match self {
Self::BonsaiDb(BonsaiError::DocumentConflict(_, _)) => true,
Self::BonsaiDb(BonsaiError::Networking(_)) => true,
_ => false,
}
}
}