use prost::{DecodeError, EncodeError};
use thiserror::Error;
#[derive(Clone, Error, Debug)]
pub enum VirtualServerError<T: std::fmt::Debug> {
#[error("External Error: {0:?}")]
InternalError(#[from] T),
#[error("{0}")]
DecodeError(DecodeError),
#[error("{0}")]
EncodeError(EncodeError),
#[error("View not found '{0}'")]
UnknownViewId(String),
#[error("Invalid JSON'{0}'")]
InvalidJSON(std::sync::Arc<serde_json::Error>),
#[error("{0}")]
Other(String),
}
pub trait ResultExt<X, T> {
fn get_internal_error(self) -> Result<X, Result<T, String>>;
}
impl<X, T: std::fmt::Debug> ResultExt<X, T> for Result<X, VirtualServerError<T>> {
fn get_internal_error(self) -> Result<X, Result<T, String>> {
match self {
Ok(x) => Ok(x),
Err(VirtualServerError::InternalError(x)) => Err(Ok(x)),
Err(x) => Err(Err(x.to_string())),
}
}
}