use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub enum DgraphError {
TxnReadOnly,
TxnFinished,
EmptyTxn,
MissingTxnContext,
WriteTxnBestEffort,
StartTsMismatch,
JwtRefreshTokenEmpty,
GrpcError(grpcio::Error),
}
impl Error for DgraphError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
DgraphError::GrpcError(grpc_error) => Some(grpc_error),
_ => None,
}
}
}
impl fmt::Display for DgraphError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
DgraphError::TxnFinished => {
write!(f, "Transaction has already been committed or discarded")
}
DgraphError::TxnReadOnly => write!(
f,
"Readonly transaction cannot run mutations or be committed"
),
DgraphError::WriteTxnBestEffort => {
write!(f, "Best effort only works for read-only queries")
}
DgraphError::EmptyTxn => write!(f, "Got empty Txn response back from query"),
DgraphError::MissingTxnContext => write!(f, "Missing Txn context on mutation response"),
DgraphError::StartTsMismatch => write!(f, "StartTs mismatch"),
DgraphError::JwtRefreshTokenEmpty => write!(f, "JWT refresh token is empty"),
DgraphError::GrpcError(ref grpc_error) => write!(f, "Grpc error: {}", grpc_error),
}
}
}
impl From<grpcio::Error> for DgraphError {
fn from(err: grpcio::Error) -> Self {
DgraphError::GrpcError(err)
}
}