Basic errors

This commit is contained in:
2021-05-18 21:14:20 +02:00
parent 7a5eea3f85
commit 806054144a
4 changed files with 61 additions and 13 deletions

34
src/error.rs Normal file
View 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()
}
}