Add error mod
This commit is contained in:
parent
72089b8545
commit
6492952dc0
41
src/error.rs
Normal file
41
src/error.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use std::fmt;
|
||||
use std::error::Error;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub enum AnkError {
|
||||
GenericError(String),
|
||||
FaucetError(String),
|
||||
NewTxError(String),
|
||||
CipherError(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for AnkError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
AnkError::GenericError(msg) => write!(f, "GenericError: {}", msg),
|
||||
AnkError::FaucetError(msg) => write!(f, "FaucetError: {}", msg),
|
||||
AnkError::NewTxError(msg) => write!(f, "NewTxError: {}", msg),
|
||||
AnkError::CipherError(msg) => write!(f, "CipherError: {}", msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for AnkError {}
|
||||
|
||||
impl From<anyhow::Error> for AnkError {
|
||||
fn from(error: anyhow::Error) -> Self {
|
||||
let error_message = error.to_string();
|
||||
|
||||
if error_message.contains("FaucetError") {
|
||||
AnkError::FaucetError(error_message)
|
||||
} else if error_message.contains("NewTxError") {
|
||||
AnkError::NewTxError(error_message)
|
||||
} else if error_message.contains("CipherError") {
|
||||
AnkError::CipherError(error_message)
|
||||
} else {
|
||||
AnkError::GenericError(error_message)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod crypto;
|
||||
pub mod network;
|
||||
pub mod silentpayments;
|
||||
pub mod error;
|
||||
|
@ -8,6 +8,7 @@ use sp_client::silentpayments::bitcoin_hashes::{sha256t_hash_newtype, Hash, Hash
|
||||
use tsify::Tsify;
|
||||
|
||||
use crate::crypto::{Aes256Decryption, CipherText, Purpose};
|
||||
use crate::error::AnkError;
|
||||
|
||||
const RAWTXTOPIC: &'static str = "rawtx";
|
||||
const RAWBLOCKTOPIC: &'static str = "rawblock";
|
||||
|
Loading…
x
Reference in New Issue
Block a user