use frame_support::sp_runtime::DispatchError;
use parity_scale_codec::Decode;
use thiserror::Error;
use crate::errors::MessageResult;
#[derive(Clone, Error, Debug)]
pub enum SessionError {
#[error("Encoding call data failed: {0}")]
Encoding(String),
#[error("Decoding call data failed: {0}")]
Decoding(String),
#[error("{0:?}")]
Drink(#[from] crate::Error),
#[error("Contract deployment has been reverted")]
DeploymentReverted,
#[error("Contract deployment failed before execution: {0:?}")]
DeploymentFailed(DispatchError),
#[error("Code upload failed: {0:?}")]
UploadFailed(DispatchError),
#[error("Contract call has been reverted. Encoded error: {0:?}")]
CallReverted(Vec<u8>),
#[error("Contract call failed before execution: {0:?}")]
CallFailed(DispatchError),
#[error("No deployed contract")]
NoContract,
#[error("Missing transcoder")]
NoTranscoder,
}
impl SessionError {
pub fn decode_revert<T: Decode>(&self) -> Result<MessageResult<T>, Self> {
match self {
SessionError::CallReverted(error) => {
Ok(MessageResult::decode(&mut &error[..]).expect("Failed to decode error"))
}
_ => Err(self.clone()),
}
}
}