Basic errors
This commit is contained in:
34
src/error.rs
Normal file
34
src/error.rs
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
pub enum ErrorKind {
|
||||
InvalidEndpoint,
|
||||
JsonParseError,
|
||||
}
|
||||
|
||||
pub struct Error {
|
||||
kind: ErrorKind,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn new(kind: ErrorKind) -> Error {
|
||||
Error {
|
||||
kind,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for Error {
|
||||
fn from(_: serde_json::Error) -> Self {
|
||||
Error {
|
||||
kind: ErrorKind::JsonParseError,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for Error {
|
||||
fn to_string(&self) -> String {
|
||||
match self.kind {
|
||||
ErrorKind::InvalidEndpoint => "invalid endpoint",
|
||||
ErrorKind::JsonParseError => "JSON parse error",
|
||||
}.to_string()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user